Skip to content

Commit 376dcbd

Browse files
committedMay 29, 2019
misc(generators): refactor
1 parent 782f56c commit 376dcbd

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
lines changed
 

‎packages/generators/init-generator.ts

+5-32
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import * as path from "path";
66
import { getPackageManager } from "@webpack-cli/utils/package-manager";
77
import { Confirm, Input, List } from "@webpack-cli/webpack-scaffold";
88

9+
import { getDefaultOptimization } from "./utils/webpackConfig";
910
import { WebpackOptions } from "./types";
1011
import entryQuestions from "./utils/entry";
11-
import langQuestionHandler, { LangType } from "./utils/language";
12-
import styleQuestionHandler, { Loader, StylingType } from "./utils/style";
12+
import langQuestionHandler, { LangType } from "./utils/languageSupport";
13+
import styleQuestionHandler, { Loader, StylingType } from "./utils/styleSupport";
1314
import tooltip from "./utils/tooltip";
1415

1516
/**
@@ -87,36 +88,8 @@ export default class InitGenerator extends Generator {
8788
"new webpack.ProgressPlugin()",
8889
);
8990

90-
let optimizationObj;
91-
92-
if (!this.isProd) {
93-
optimizationObj = {
94-
splitChunks: {
95-
chunks: "'all'",
96-
},
97-
};
98-
} else {
99-
optimizationObj = {
100-
minimizer: [
101-
"new TerserPlugin()",
102-
],
103-
splitChunks: {
104-
cacheGroups: {
105-
vendors: {
106-
priority: -10,
107-
test: "/[\\\\/]node_modules[\\\\/]/",
108-
},
109-
},
110-
chunks: "'async'",
111-
minChunks: 1,
112-
minSize: 30000,
113-
// for production name is recommended to be off
114-
name: !this.isProd,
115-
},
116-
};
117-
}
118-
119-
this.configuration.config.webpackOptions.optimization = optimizationObj;
91+
let optimizationConfig = getDefaultOptimization(this.isProd);
92+
this.configuration.config.webpackOptions.optimization = optimizationConfig;
12093

12194
if (!this.isProd) {
12295
this.configuration.config.webpackOptions.devServer = {
File renamed without changes.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { WebpackOptions } from '../types';
2+
3+
export function getDefaultOptimization(isProd: boolean): WebpackOptions["optimization"] {
4+
let optimizationOptions;
5+
if (isProd) {
6+
optimizationOptions = {
7+
splitChunks: {
8+
chunks: "'all'",
9+
},
10+
};
11+
} else {
12+
optimizationOptions = {
13+
minimizer: [
14+
"new TerserPlugin()",
15+
],
16+
splitChunks: {
17+
cacheGroups: {
18+
vendors: {
19+
priority: -10,
20+
test: "/[\\\\/]node_modules[\\\\/]/",
21+
},
22+
},
23+
chunks: "'async'",
24+
minChunks: 1,
25+
minSize: 30000,
26+
// for production name is recommended to be off
27+
name: !this.isProd,
28+
},
29+
};
30+
}
31+
return optimizationOptions;
32+
}

‎packages/webpack-scaffold/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const validation = value => {
192192
if (value.length > 4) {
193193
return true;
194194
} else {
195-
return "The entry point must be longer than 4, try again";
195+
return "Your answer must be longer than 4, try again";
196196
}
197197
};
198198
InputValidate("entry", "what is your entry point?", validation, "src/index");

0 commit comments

Comments
 (0)
Please sign in to comment.