Skip to content

Commit

Permalink
misc(init-generator): use webpackOption types, improve test rules
Browse files Browse the repository at this point in the history
  • Loading branch information
misterdev committed May 28, 2019
1 parent 85ef3e7 commit a650e0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/generators/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export interface WebpackOptions {
};
}

interface Rule {
export interface Rule {
enforce?: "pre" | "post";
exclude?: IRuleSetCondition;
include?: IRuleSetCondition;
Expand Down
27 changes: 8 additions & 19 deletions packages/generators/utils/language.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { Rule } from "../types";

export enum LangType {
ES6 = "ES6",
Typescript = "Typescript",
}

interface ModuleRule extends Object {
include?: string[];
exclude?: string[];
loader: string;
options?: {
plugins: string[];
presets: Preset[][];
};
test: string;
}

type Preset = string | object;

const replaceExt = (path: string, ext: string): string =>
path.substr(0, path.lastIndexOf(".")) + `${ext}'`;

Expand Down Expand Up @@ -54,14 +43,14 @@ function getEntryFolders(self): string[] {
*
* Returns an module.rule object for the babel loader
* @param {string[]} includeFolders An array of folders to include
* @returns {ModuleRule} A configuration containing the babel-loader with env preset
* @returns {Rule} A configuration containing the babel-loader with env preset
*/
export function getBabelLoader(includeFolders: string[]): ModuleRule {
export function getBabelLoader(includeFolders: string[]): Rule {
const include = includeFolders.map((folder: string): string =>
`path.resolve(__dirname, '${folder}')`
);
return {
test: "/\.js$/",
test: "/\.(js|jsx)$/",
include,
loader: "'babel-loader'",
options: {
Expand All @@ -82,14 +71,14 @@ export function getBabelLoader(includeFolders: string[]): ModuleRule {
*
* Returns an module.rule object for the typescript loader
* @param {string[]} includeFolders An array of folders to include
* @returns {ModuleRule} A configuration containing the ts-loader
* @returns {Rule} A configuration containing the ts-loader
*/
export function getTypescriptLoader(includeFolders: string[]): ModuleRule {
export function getTypescriptLoader(includeFolders: string[]): Rule {
const include = includeFolders.map((folder: string): string =>
`path.resolve(__dirname, '${folder}')`
);
return {
test: "/\.tsx?$/",
test: "/\.(ts|tsx)?$/",
loader: "'ts-loader'",
include,
exclude: ["/node_modules/"],
Expand Down

0 comments on commit a650e0e

Please sign in to comment.