Skip to content

Commit

Permalink
Update UglifyJSPlugin transformation (#401)
Browse files Browse the repository at this point in the history
* cli(migration): Update UglifyJS migration file to fit webpack4 configuration

* cli(migration): Add cases where require variable does not need to exist

* cli(migration): Add transformation for usage of webpack.otimization.UglifyPlugin

* cli(tests): Update test snapshots after updating transformation

* cli(fix): fix expressionContent being null

* cli(refactor): remove plugins array if empty

Created function on ast-utils so every other transformation can use this.

* tests: add tests for new ast-utils method

* fix: fix test names and jsdoc

* fix: update maxSize for utils folder
  • Loading branch information
matheus1lva authored and evenstensberg committed Apr 18, 2018
1 parent d10488b commit 65c46e0
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 83 deletions.
64 changes: 24 additions & 40 deletions lib/migrate/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,32 @@ module.exports = {
exports[`transform should respect recast options 1`] = `
"
module.exports = {
devtool: 'eval',
entry: [
devtool: 'eval',
entry: [
'./src/index'
],
output: {
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
module: {
rules: [{
test: /\.js$/,
test: /.js$/,
use: [{
loader: \\"babel-loader\\",
}],
include: path.join(__dirname, 'src')
}]
},
resolve: {
resolve: {
modules: ['node_modules', path.resolve('/src')],
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
}),
new webpack.LoaderOptionsPlugin({
debug: true,
minimize: true,
})
],
plugins: [new webpack.LoaderOptionsPlugin({
debug: true,
})],
optimization: {
minimize: true,
}
};
"
`;
Expand Down Expand Up @@ -135,40 +127,32 @@ module.exports = {
exports[`transform should transform using all transformations 1`] = `
"
module.exports = {
devtool: 'eval',
entry: [
devtool: 'eval',
entry: [
'./src/index'
],
output: {
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
module: {
rules: [{
test: /\.js$/,
test: /.js$/,
use: [{
loader: 'babel-loader'
}],
include: path.join(__dirname, 'src')
}]
},
resolve: {
resolve: {
modules: ['node_modules', path.resolve('/src')]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
new webpack.LoaderOptionsPlugin({
debug: true,
minimize: true
})
]
plugins: [new webpack.LoaderOptionsPlugin({
debug: true
})],
optimization: {
minimize: true
}
};
"
`;
118 changes: 100 additions & 18 deletions lib/migrate/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,118 @@

exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-0" data 1`] = `
"module.exports = {
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
})
]
optimization: {
minimize: true
}
}
"
`;

exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-1" data 1`] = `
"module.exports = {
"const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
devtool: \\"source-map\\",
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
})
]
optimization: {
minimize: true,
minimizer: [new UglifyJsPlugin({
sourceMap: true,
compress: {}
})]
}
}
"
`;

exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-2" data 1`] = `
"const Uglify = require('uglifyjs-webpack-plugin');
module.exports = {
devtool: \\"source-map\\",
optimization: {
minimize: true,
minimizer: [new Uglify({
sourceMap: true,
compress: {}
})]
}
}
"
`;

exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-3" data 1`] = `
"module.exports = {
devtool: \\"cheap-source-map\\",
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {},
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
loaders: [{
test: /.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
},
resolve: {
root: path.resolve('/src'),
modules: ['node_modules']
},
plugins: [new webpack.optimize.OccurrenceOrderPlugin()],
debug: true,
optimization: {
minimize: true
}
};
"
`;

exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-4" data 1`] = `
"const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
loaders: [{
test: /.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
},
resolve: {
root: path.resolve('/src'),
modules: ['node_modules']
},
plugins: [new webpack.optimize.OccurrenceOrderPlugin()],
debug: true,
optimization: {
minimize: true,
minimizer: [new UglifyJsPlugin({
sourceMap: true
})
]
}
})]
}
};
"
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
plugins: [
new webpack.optimize.UglifyJsPlugin()
new UglifyJsPlugin()
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
devtool: "source-map",
plugins: [
new webpack.optimize.UglifyJsPlugin({})
new UglifyJsPlugin({
sourceMap: true,
compress: {}
})
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const Uglify = require('uglifyjs-webpack-plugin');
module.exports = {
devtool: "cheap-source-map",
devtool: "source-map",
plugins: [
new webpack.optimize.UglifyJsPlugin({
new Uglify({
sourceMap: true,
compress: {}
})
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
loaders: [{
test: /.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
},
resolve: {
root: path.resolve('/src'),
modules: ['node_modules']
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
loaders: [{
test: /.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
},
resolve: {
root: path.resolve('/src'),
modules: ['node_modules']
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
};
Loading

0 comments on commit 65c46e0

Please sign in to comment.