Skip to content

Commit

Permalink
misc(generators): refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
misterdev committed May 29, 2019
1 parent 782f56c commit 376dcbd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
37 changes: 5 additions & 32 deletions packages/generators/init-generator.ts
Expand Up @@ -6,10 +6,11 @@ import * as path from "path";
import { getPackageManager } from "@webpack-cli/utils/package-manager";
import { Confirm, Input, List } from "@webpack-cli/webpack-scaffold";

import { getDefaultOptimization } from "./utils/webpackConfig";
import { WebpackOptions } from "./types";
import entryQuestions from "./utils/entry";
import langQuestionHandler, { LangType } from "./utils/language";
import styleQuestionHandler, { Loader, StylingType } from "./utils/style";
import langQuestionHandler, { LangType } from "./utils/languageSupport";
import styleQuestionHandler, { Loader, StylingType } from "./utils/styleSupport";
import tooltip from "./utils/tooltip";

/**
Expand Down Expand Up @@ -87,36 +88,8 @@ export default class InitGenerator extends Generator {
"new webpack.ProgressPlugin()",
);

let optimizationObj;

if (!this.isProd) {
optimizationObj = {
splitChunks: {
chunks: "'all'",
},
};
} else {
optimizationObj = {
minimizer: [
"new TerserPlugin()",
],
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: "/[\\\\/]node_modules[\\\\/]/",
},
},
chunks: "'async'",
minChunks: 1,
minSize: 30000,
// for production name is recommended to be off
name: !this.isProd,
},
};
}

this.configuration.config.webpackOptions.optimization = optimizationObj;
let optimizationConfig = getDefaultOptimization(this.isProd);
this.configuration.config.webpackOptions.optimization = optimizationConfig;

if (!this.isProd) {
this.configuration.config.webpackOptions.devServer = {
Expand Down
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions packages/generators/utils/webpackConfig.ts
@@ -0,0 +1,32 @@
import { WebpackOptions } from '../types';

export function getDefaultOptimization(isProd: boolean): WebpackOptions["optimization"] {
let optimizationOptions;
if (isProd) {
optimizationOptions = {
splitChunks: {
chunks: "'all'",
},
};
} else {
optimizationOptions = {
minimizer: [
"new TerserPlugin()",
],
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: "/[\\\\/]node_modules[\\\\/]/",
},
},
chunks: "'async'",
minChunks: 1,
minSize: 30000,
// for production name is recommended to be off
name: !this.isProd,
},
};
}
return optimizationOptions;
}
2 changes: 1 addition & 1 deletion packages/webpack-scaffold/README.md
Expand Up @@ -192,7 +192,7 @@ const validation = value => {
if (value.length > 4) {
return true;
} else {
return "The entry point must be longer than 4, try again";
return "Your answer must be longer than 4, try again";
}
};
InputValidate("entry", "what is your entry point?", validation, "src/index");
Expand Down

0 comments on commit 376dcbd

Please sign in to comment.