Skip to content

Commit 4f8ebee

Browse files
matheus1lvaematipico
authored andcommitted
cli(migration): update UglifyJS transformation (#416)
* 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
1 parent 1761666 commit 4f8ebee

13 files changed

Lines changed: 330 additions & 83 deletions

lib/migrate/__snapshots__/index.test.js.snap

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,40 +61,32 @@ module.exports = {
6161
exports[`transform should respect recast options 1`] = `
6262
"
6363
module.exports = {
64-
devtool: 'eval',
65-
66-
entry: [
64+
devtool: 'eval',
65+
entry: [
6766
'./src/index'
6867
],
69-
70-
output: {
68+
output: {
7169
path: path.join(__dirname, 'dist'),
7270
filename: 'index.js'
7371
},
74-
75-
module: {
72+
module: {
7673
rules: [{
77-
test: /\.js$/,
74+
test: /.js$/,
7875
use: [{
7976
loader: \\"babel-loader\\",
8077
}],
8178
include: path.join(__dirname, 'src')
8279
}]
8380
},
84-
85-
resolve: {
81+
resolve: {
8682
modules: ['node_modules', path.resolve('/src')],
8783
},
88-
89-
plugins: [
90-
new webpack.optimize.UglifyJsPlugin({
91-
sourceMap: true,
92-
}),
93-
new webpack.LoaderOptionsPlugin({
94-
debug: true,
95-
minimize: true,
96-
})
97-
],
84+
plugins: [new webpack.LoaderOptionsPlugin({
85+
debug: true,
86+
})],
87+
optimization: {
88+
minimize: true,
89+
}
9890
};
9991
"
10092
`;
@@ -135,40 +127,32 @@ module.exports = {
135127
exports[`transform should transform using all transformations 1`] = `
136128
"
137129
module.exports = {
138-
devtool: 'eval',
139-
140-
entry: [
130+
devtool: 'eval',
131+
entry: [
141132
'./src/index'
142133
],
143-
144-
output: {
134+
output: {
145135
path: path.join(__dirname, 'dist'),
146136
filename: 'index.js'
147137
},
148-
149-
module: {
138+
module: {
150139
rules: [{
151-
test: /\.js$/,
140+
test: /.js$/,
152141
use: [{
153142
loader: 'babel-loader'
154143
}],
155144
include: path.join(__dirname, 'src')
156145
}]
157146
},
158-
159-
resolve: {
147+
resolve: {
160148
modules: ['node_modules', path.resolve('/src')]
161149
},
162-
163-
plugins: [
164-
new webpack.optimize.UglifyJsPlugin({
165-
sourceMap: true
166-
}),
167-
new webpack.LoaderOptionsPlugin({
168-
debug: true,
169-
minimize: true
170-
})
171-
]
150+
plugins: [new webpack.LoaderOptionsPlugin({
151+
debug: true
152+
})],
153+
optimization: {
154+
minimize: true
155+
}
172156
};
173157
"
174158
`;

lib/migrate/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap

Lines changed: 100 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,118 @@
22

33
exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-0" data 1`] = `
44
"module.exports = {
5-
plugins: [
6-
new webpack.optimize.UglifyJsPlugin({
7-
sourceMap: true
8-
})
9-
]
5+
optimization: {
6+
minimize: true
7+
}
108
}
119
"
1210
`;
1311

1412
exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-1" data 1`] = `
15-
"module.exports = {
13+
"const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
14+
module.exports = {
1615
devtool: \\"source-map\\",
17-
plugins: [
18-
new webpack.optimize.UglifyJsPlugin({
19-
sourceMap: true
20-
})
21-
]
16+
optimization: {
17+
minimize: true,
18+
19+
minimizer: [new UglifyJsPlugin({
20+
sourceMap: true,
21+
compress: {}
22+
})]
23+
}
2224
}
2325
"
2426
`;
2527

2628
exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-2" data 1`] = `
29+
"const Uglify = require('uglifyjs-webpack-plugin');
30+
module.exports = {
31+
devtool: \\"source-map\\",
32+
optimization: {
33+
minimize: true,
34+
35+
minimizer: [new Uglify({
36+
sourceMap: true,
37+
compress: {}
38+
})]
39+
}
40+
}
41+
"
42+
`;
43+
44+
exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-3" data 1`] = `
2745
"module.exports = {
28-
devtool: \\"cheap-source-map\\",
29-
plugins: [
30-
new webpack.optimize.UglifyJsPlugin({
31-
compress: {},
46+
devtool: 'eval',
47+
48+
entry: [
49+
'./src/index'
50+
],
51+
52+
output: {
53+
path: path.join(__dirname, 'dist'),
54+
filename: 'index.js'
55+
},
56+
57+
module: {
58+
loaders: [{
59+
test: /.js$/,
60+
loaders: ['babel'],
61+
include: path.join(__dirname, 'src')
62+
}]
63+
},
64+
65+
resolve: {
66+
root: path.resolve('/src'),
67+
modules: ['node_modules']
68+
},
69+
70+
plugins: [new webpack.optimize.OccurrenceOrderPlugin()],
71+
debug: true,
72+
73+
optimization: {
74+
minimize: true
75+
}
76+
};
77+
"
78+
`;
79+
80+
exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-4" data 1`] = `
81+
"const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
82+
module.exports = {
83+
devtool: 'eval',
84+
85+
entry: [
86+
'./src/index'
87+
],
88+
89+
output: {
90+
path: path.join(__dirname, 'dist'),
91+
filename: 'index.js'
92+
},
93+
94+
module: {
95+
loaders: [{
96+
test: /.js$/,
97+
loaders: ['babel'],
98+
include: path.join(__dirname, 'src')
99+
}]
100+
},
101+
102+
resolve: {
103+
root: path.resolve('/src'),
104+
modules: ['node_modules']
105+
},
106+
107+
plugins: [new webpack.optimize.OccurrenceOrderPlugin()],
108+
debug: true,
109+
110+
optimization: {
111+
minimize: true,
112+
113+
minimizer: [new UglifyJsPlugin({
32114
sourceMap: true
33-
})
34-
]
35-
}
115+
})]
116+
}
117+
};
36118
"
37119
`;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
2+
13
module.exports = {
24
plugins: [
3-
new webpack.optimize.UglifyJsPlugin()
5+
new UglifyJsPlugin()
46
]
57
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
12
module.exports = {
23
devtool: "source-map",
34
plugins: [
4-
new webpack.optimize.UglifyJsPlugin({})
5+
new UglifyJsPlugin({
6+
sourceMap: true,
7+
compress: {}
8+
})
59
]
610
}

lib/migrate/uglifyJsPlugin/__testfixtures__/uglifyJsPlugin-2.input.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
const Uglify = require('uglifyjs-webpack-plugin');
12
module.exports = {
2-
devtool: "cheap-source-map",
3+
devtool: "source-map",
34
plugins: [
4-
new webpack.optimize.UglifyJsPlugin({
5+
new Uglify({
6+
sourceMap: true,
57
compress: {}
68
})
79
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
devtool: 'eval',
3+
entry: [
4+
'./src/index'
5+
],
6+
output: {
7+
path: path.join(__dirname, 'dist'),
8+
filename: 'index.js'
9+
},
10+
module: {
11+
loaders: [{
12+
test: /.js$/,
13+
loaders: ['babel'],
14+
include: path.join(__dirname, 'src')
15+
}]
16+
},
17+
resolve: {
18+
root: path.resolve('/src'),
19+
modules: ['node_modules']
20+
},
21+
plugins: [
22+
new webpack.optimize.UglifyJsPlugin(),
23+
new webpack.optimize.OccurrenceOrderPlugin()
24+
],
25+
debug: true
26+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
devtool: 'eval',
3+
entry: [
4+
'./src/index'
5+
],
6+
output: {
7+
path: path.join(__dirname, 'dist'),
8+
filename: 'index.js'
9+
},
10+
module: {
11+
loaders: [{
12+
test: /.js$/,
13+
loaders: ['babel'],
14+
include: path.join(__dirname, 'src')
15+
}]
16+
},
17+
resolve: {
18+
root: path.resolve('/src'),
19+
modules: ['node_modules']
20+
},
21+
plugins: [
22+
new webpack.optimize.UglifyJsPlugin({
23+
sourceMap: true
24+
}),
25+
new webpack.optimize.OccurrenceOrderPlugin()
26+
],
27+
debug: true
28+
};

0 commit comments

Comments
 (0)