Skip to content

Commit 9553557

Browse files
committed
cli(init): Add cachingGroup's defaults, fix entry
1 parent eafcb98 commit 9553557

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

lib/generators/init-generator.js

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ module.exports = class InitGenerator extends Generator {
114114
})
115115
.then(prodConfirmAnswer => {
116116
this.isProd = prodConfirmAnswer["prodConfirm"];
117-
this.configuration.config.webpackOptions.mode =
118-
this.isProd ? `"${"production"}"` : `"${"development"}"`;
117+
this.configuration.config.webpackOptions.mode = this.isProd ? "'production'" : "'development'";
119118
})
120119
.then(() => {
121120
return this.prompt([
@@ -376,39 +375,27 @@ module.exports = class InitGenerator extends Generator {
376375
}
377376
}
378377
// add splitChunks options for transparency
379-
const { entry } = this.configuration.config.webpackOptions;
380378
this.configuration.config.topScope.push(tooltip.splitChunks());
381379
this.configuration.config.webpackOptions.optimization = {
382380
splitChunks: {
383381
chunks: "'async'",
384-
minChunks: 1,
385382
minSize: 30000,
383+
minChunks: 1,
384+
// for production name is recommended to be off
385+
name: !this.isProd,
386+
cacheGroups: {
387+
vendors: {
388+
test: "/[\\\\/]node_modules[\\\\/]/",
389+
priority: -10
390+
},
391+
},
392+
default: {
393+
minChunks: 2,
394+
priority: -20,
395+
reuseExistingChunk: true
396+
}
386397
}
387398
};
388-
389-
// for production name is recommended to be off
390-
if (this.isProd) {
391-
this.configuration.config.webpackOptions.optimization.splitChunks.name = false;
392-
}
393-
394-
if (entry && typeof entry === "object") {
395-
// if user had provided multiple entry points, we make cacheGroup example
396-
// per entry point
397-
const entries = Object.keys(entry);
398-
if (entries.length > 1) {
399-
this.configuration.config.webpackOptions.optimization.splitChunks.cacheGroups = {};
400-
entries.map(item => {
401-
const newCacheGroup = {
402-
chunks: "'all'",
403-
// TODO: implement RegExp from entry for test value of caching group
404-
};
405-
if (!this.isProd) {
406-
newCacheGroup.name = `'${item}'`;
407-
}
408-
this.configuration.config.webpackOptions.optimization.splitChunks.cacheGroups[item] = newCacheGroup;
409-
});
410-
}
411-
}
412399
done();
413400
});
414401
}

lib/generators/utils/entry.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = (self, answer) => {
2020
.prompt([
2121
InputValidate(
2222
"multipleEntries",
23-
"Type the names you want for your modules (entry files), separated by comma [example: 'app,vendor']",
23+
"Type the names you want for your modules (entry files), separated by comma [example: app,vendor]",
2424
validate
2525
)
2626
])
@@ -40,7 +40,7 @@ module.exports = (self, answer) => {
4040
!n[val].includes("path") &&
4141
!n[val].includes("process")
4242
) {
43-
n[val] = `"${n[val]}.js"`;
43+
n[val] = `"'${n[val]}.js'"`;
4444
}
4545
webpackEntryPoint[val] = n[val];
4646
});
@@ -55,7 +55,7 @@ module.exports = (self, answer) => {
5555
self.prompt([
5656
InputValidate(
5757
`${entryProp}`,
58-
`What is the location of "${entryProp}"? [example: './src/${entryProp}']`,
58+
`What is the location of "${entryProp}"? [example: ./src/${entryProp}]`,
5959
validate
6060
)
6161
])
@@ -68,7 +68,7 @@ module.exports = (self, answer) => {
6868
!propAns[val].includes("path") &&
6969
!propAns[val].includes("process")
7070
) {
71-
propAns[val] = `"${propAns[val]}.js"`;
71+
propAns[val] = `"'${propAns[val]}.js'"`;
7272
}
7373
webpackEntryPoint[val] = propAns[val];
7474
});
@@ -80,7 +80,7 @@ module.exports = (self, answer) => {
8080
.prompt([
8181
InputValidate(
8282
"singularEntry",
83-
"Which module will be the first to enter the application? [default: './src/index']"
83+
"Which module will be the first to enter the application? [default: ./src/index]"
8484
)
8585
])
8686
.then(singularAnswer => `"${singularAnswer["singularEntry"]}"`);

lib/generators/utils/tooltip.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = {
2727
* It is safe to remove "splitChunks" from the generated configuration
2828
* and was added as an educational example.
2929
*
30-
* Documentation page will be available here soon:
3130
* https://webpack.js.org/plugins/split-chunks-plugin/
3231
*
3332
*/`;

0 commit comments

Comments
 (0)