-
-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli(init): webpack4 ready #356
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c0997de
cli(init): webpack4 ready
EugeneHlushko 6aedd20
cli(init): remove unused variable, still @next on etwp
EugeneHlushko 6554ffd
cli(init): Allow to use default entry in `init`
EugeneHlushko 8175a9b
cli(init): Fix typo in comment
EugeneHlushko 114a0c2
cli(init): Optimization transform and tests
EugeneHlushko 9f08f33
cli(init): Fix non-optimized option for splitChunks
EugeneHlushko eafcb98
cli(init): Add cachingGroup per entry, don't show name in prod
EugeneHlushko 9553557
cli(init): Add cachingGroup's defaults, fix entry
EugeneHlushko 1177b44
cli(init): Add a link to where the defaults live
EugeneHlushko 4b1edb7
cli(init): Remove default caching group definition from example
EugeneHlushko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,17 @@ module.exports = { | |
* | ||
*/`; | ||
}, | ||
commonsChunk: _ => { | ||
splitChunks: _ => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good stuff :3 |
||
return `/* | ||
* We've enabled commonsChunkPlugin for you. This allows your app to | ||
* load faster and it splits the modules you provided as entries across | ||
* different bundles! | ||
* SplitChunksPlugin is enabled by default and replaced | ||
* deprecated CommonsChunkPlugin. It automatically identifies modules which | ||
* should be splitted of chunk by heuristics using module duplication count and | ||
* module category (i. e. node_modules). And splits the chunks… | ||
* | ||
* https://webpack.js.org/plugins/commons-chunk-plugin/ | ||
* It is safe to remove "splitChunks" from the generated configuration | ||
* and was added as an educational example. | ||
* | ||
* https://webpack.js.org/plugins/split-chunks-plugin/ | ||
* | ||
*/`; | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
lib/init/transformations/optimization/__snapshots__/optimization.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`optimization transforms correctly using "optimization-0" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
|
||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
optimization: { | ||
splitChunks: { | ||
minSize: 1, | ||
chunks: 'all' | ||
} | ||
} | ||
} | ||
" | ||
`; |
6 changes: 6 additions & 0 deletions
6
lib/init/transformations/optimization/__testfixtures__/optimization-0.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use strict"; | ||
|
||
const utils = require("../../../utils/ast-utils"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is okay for now, GSOC participants will fix the rest of missing stuff =) |
||
|
||
/** | ||
* | ||
* Transform for optimization. Finds the optimization property from yeoman and creates a | ||
* property based on what the user has given us. | ||
* | ||
* @param j — jscodeshift API | ||
* @param ast - jscodeshift API | ||
* @param {any} webpackProperties - transformation object to scaffold | ||
* @param {String} action - action that indicates what to be done to the AST | ||
* @returns ast - jscodeshift API | ||
*/ | ||
|
||
module.exports = function profileTransform(j, ast, webpackProperties, action) { | ||
function createProfileProperty(p) { | ||
utils.pushCreateProperty(j, p, "optimization", j.objectExpression([])); | ||
return utils.pushObjectKeys(j, p, webpackProperties, "optimization"); | ||
} | ||
|
||
if (webpackProperties || typeof webpackProperties === "boolean") { | ||
if (action === "init" && typeof webpackProperties === "object") { | ||
return ast | ||
.find(j.ObjectExpression) | ||
.filter(p => utils.isAssignment(null, p, createProfileProperty)); | ||
} else if ( | ||
action === "init" && | ||
(webpackProperties.length || typeof webpackProperties === "boolean") | ||
) { | ||
return ast | ||
.find(j.ObjectExpression) | ||
.filter(p => | ||
utils.isAssignment( | ||
j, | ||
p, | ||
utils.pushCreateProperty, | ||
"optimization", | ||
webpackProperties | ||
) | ||
); | ||
} else if (action === "add") { | ||
// TODO | ||
} else if (action === "remove") { | ||
// TODO | ||
} else if (action === "update") { | ||
// TODO | ||
} | ||
} else { | ||
return ast; | ||
} | ||
}; |
16 changes: 16 additions & 0 deletions
16
lib/init/transformations/optimization/optimization.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use strict"; | ||
|
||
const defineTest = require("../../../utils/defineTest"); | ||
|
||
defineTest( | ||
__dirname, | ||
"optimization", | ||
"optimization-0", | ||
{ | ||
splitChunks: { | ||
minSize: 1, | ||
chunks: "'all'" | ||
} | ||
}, | ||
"init" | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this to split groups of chunks.