-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cli(init): webpack4 ready * cli(init): remove unused variable, still @next on etwp * cli(init): Allow to use default entry in `init` * cli(init): Fix typo in comment * cli(init): Optimization transform and tests * cli(init): Fix non-optimized option for splitChunks * cli(init): Add cachingGroup per entry, don't show name in prod * cli(init): Add cachingGroup's defaults, fix entry * cli(init): Add a link to where the defaults live * cli(init): Remove default caching group definition from example
- Loading branch information
1 parent
c94888d
commit 3bbd428
Showing
8 changed files
with
142 additions
and
38 deletions.
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
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"); | ||
|
||
/** | ||
* | ||
* 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" | ||
); |