Skip to content

Commit a650e0e

Browse files
committedMay 28, 2019
misc(init-generator): use webpackOption types, improve test rules
1 parent 85ef3e7 commit a650e0e

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed
 

‎packages/generators/types/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export interface WebpackOptions {
214214
};
215215
}
216216

217-
interface Rule {
217+
export interface Rule {
218218
enforce?: "pre" | "post";
219219
exclude?: IRuleSetCondition;
220220
include?: IRuleSetCondition;

‎packages/generators/utils/language.ts

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1+
import { Rule } from "../types";
2+
13
export enum LangType {
24
ES6 = "ES6",
35
Typescript = "Typescript",
46
}
57

6-
interface ModuleRule extends Object {
7-
include?: string[];
8-
exclude?: string[];
9-
loader: string;
10-
options?: {
11-
plugins: string[];
12-
presets: Preset[][];
13-
};
14-
test: string;
15-
}
16-
17-
type Preset = string | object;
18-
198
const replaceExt = (path: string, ext: string): string =>
209
path.substr(0, path.lastIndexOf(".")) + `${ext}'`;
2110

@@ -54,14 +43,14 @@ function getEntryFolders(self): string[] {
5443
*
5544
* Returns an module.rule object for the babel loader
5645
* @param {string[]} includeFolders An array of folders to include
57-
* @returns {ModuleRule} A configuration containing the babel-loader with env preset
46+
* @returns {Rule} A configuration containing the babel-loader with env preset
5847
*/
59-
export function getBabelLoader(includeFolders: string[]): ModuleRule {
48+
export function getBabelLoader(includeFolders: string[]): Rule {
6049
const include = includeFolders.map((folder: string): string =>
6150
`path.resolve(__dirname, '${folder}')`
6251
);
6352
return {
64-
test: "/\.js$/",
53+
test: "/\.(js|jsx)$/",
6554
include,
6655
loader: "'babel-loader'",
6756
options: {
@@ -82,14 +71,14 @@ export function getBabelLoader(includeFolders: string[]): ModuleRule {
8271
*
8372
* Returns an module.rule object for the typescript loader
8473
* @param {string[]} includeFolders An array of folders to include
85-
* @returns {ModuleRule} A configuration containing the ts-loader
74+
* @returns {Rule} A configuration containing the ts-loader
8675
*/
87-
export function getTypescriptLoader(includeFolders: string[]): ModuleRule {
76+
export function getTypescriptLoader(includeFolders: string[]): Rule {
8877
const include = includeFolders.map((folder: string): string =>
8978
`path.resolve(__dirname, '${folder}')`
9079
);
9180
return {
92-
test: "/\.tsx?$/",
81+
test: "/\.(ts|tsx)?$/",
9382
loader: "'ts-loader'",
9483
include,
9584
exclude: ["/node_modules/"],

0 commit comments

Comments
 (0)
Please sign in to comment.