Skip to content

Commit

Permalink
cli(init): Add cachingGroup per entry, don't show name in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneHlushko committed Mar 25, 2018
1 parent fb83ead commit 27ad714
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
30 changes: 28 additions & 2 deletions lib/generators/init-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,39 @@ module.exports = class InitGenerator extends Generator {
}
}
// add splitChunks options for transparency
const { entry } = this.configuration.config.webpackOptions;
this.configuration.config.topScope.push(tooltip.splitChunks());
this.configuration.config.webpackOptions.optimization = {
splitChunks: {
chunks: "'all'",
minChunks: 1
chunks: "'async'",
minChunks: 1,
minSize: 30000,
}
};

// for production name is recommended to be off
if (this.isProd) {
this.configuration.config.webpackOptions.optimization.splitChunks.name = false;
}

if (entry && typeof entry === "object") {
// if user had provided multiple entry points, we make cacheGroup example
// per entry point
const entries = Object.keys(entry);
if (entries.length > 1) {
this.configuration.config.webpackOptions.optimization.splitChunks.cacheGroups = {};
entries.map(item => {
const newCacheGroup = {
chunks: "'all'",
// TODO: implement RegExp from entry for test value of caching group
};
if (!this.isProd) {
newCacheGroup.name = `'${item}'`;
}
this.configuration.config.webpackOptions.optimization.splitChunks.cacheGroups[item] = newCacheGroup;
});
}
}
done();
});
}
Expand Down
14 changes: 7 additions & 7 deletions lib/generators/utils/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ module.exports = (self, answer) => {
if (
n[val].charAt(0) !== "(" &&
n[val].charAt(0) !== "[" &&
n[val].indexOf("function") < 0 &&
n[val].indexOf("path") < 0 &&
n[val].indexOf("process") < 0
!n[val].includes("function") &&
!n[val].includes("path") &&
!n[val].includes("process")
) {
n[val] = `"${n[val]}.js"`;
}
Expand All @@ -55,7 +55,7 @@ module.exports = (self, answer) => {
self.prompt([
InputValidate(
`${entryProp}`,
`What is the location of "${entryProp}"? [example: "./src/${entryProp}"]`,
`What is the location of "${entryProp}"? [example: './src/${entryProp}']`,
validate
)
])
Expand All @@ -64,9 +64,9 @@ module.exports = (self, answer) => {
if (
propAns[val].charAt(0) !== "(" &&
propAns[val].charAt(0) !== "[" &&
propAns[val].indexOf("function") < 0 &&
propAns[val].indexOf("path") < 0 &&
propAns[val].indexOf("process") < 0
!propAns[val].includes("function") &&
!propAns[val].includes("path") &&
!propAns[val].includes("process")
) {
propAns[val] = `"${propAns[val]}.js"`;
}
Expand Down

0 comments on commit 27ad714

Please sign in to comment.