Skip to content

Commit

Permalink
fix: Do not create LoaderOptionsPlugin if loaderOptions is empty (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
okonet committed Feb 24, 2017
1 parent a46edbb commit b9d22c9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
exports[`loaderOptionsPlugin transforms correctly 1`] = `
exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-0" data 1`] = `
"// Do not create LoaderOptionsPlugin is not necessary
module.exports = {
plugins: [
new SomePlugin()
]
}
"
`;

exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-1" data 1`] = `
"module.exports = {
debug: true,
plugins: [
Expand All @@ -12,3 +22,16 @@ exports[`loaderOptionsPlugin transforms correctly 1`] = `
}
"
`;

exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-2" data 1`] = `
"// Don\'t modify LoaderOptionsPlugin
module.exports = {
plugins: [
new SomePlugin(),
new webpack.optimize.LoaderOptionsPlugin({
foo: \'bar\'
})
]
}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Do not create LoaderOptionsPlugin is not necessary
module.exports = {
plugins: [
new SomePlugin()
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Don't modify LoaderOptionsPlugin
module.exports = {
plugins: [
new SomePlugin(),
new webpack.optimize.LoaderOptionsPlugin({
foo: 'bar'
})
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const isEmpty = require('lodash/isEmpty');
const findPluginsByName = require('../utils').findPluginsByName;
const createOrUpdatePluginByName = require('../utils').createOrUpdatePluginByName;

Expand All @@ -20,6 +21,7 @@ module.exports = function(j, ast) {
.find(j.ArrayExpression)
.filter(path => path.parent.value.key.name === 'plugins')
.forEach(path => {
!isEmpty(loaderOptions) &&
createOrUpdatePluginByName(j, path, 'webpack.optimize.LoaderOptionsPlugin', loaderOptions);
});
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const defineTest = require('../defineTest');

defineTest(__dirname, 'loaderOptionsPlugin');
defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-0');
defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-1');
defineTest(__dirname, 'loaderOptionsPlugin', 'loaderOptionsPlugin-2');
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"interpret": "^1.0.1",
"jscodeshift": "^0.3.30",
"loader-utils": "^0.2.16",
"lodash": "^4.17.4",
"recast": "git://github.com/kalcifer/recast.git#bug/allowbreak",
"rx": "^4.1.0",
"supports-color": "^3.1.2",
Expand Down

0 comments on commit b9d22c9

Please sign in to comment.