Skip to content

Commit

Permalink
fix: reset files
Browse files Browse the repository at this point in the history
Move files back to uglify
  • Loading branch information
abenezerabebe authored and sendilkumarn committed Mar 16, 2019
1 parent ef23fec commit 9863445
Show file tree
Hide file tree
Showing 20 changed files with 398 additions and 82 deletions.
8 changes: 4 additions & 4 deletions MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Given a basic configuration file like so:
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');

module.exports = {
Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = {
},

plugins: [
new TerserPlugin(),
new UglifyJSPlugin(),

new ExtractTextPlugin('styles-[contentHash].css'),

Expand Down Expand Up @@ -115,7 +115,7 @@ After it has run, we have our new webpack config file!
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');

module.exports = {
Expand Down Expand Up @@ -154,7 +154,7 @@ module.exports = {
},

plugins: [
new TerserPlugin(),
new UglifyJSPlugin(),

new ExtractTextPlugin('styles-[contentHash].css'),

Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/generators/init-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class InitGenerator extends Generator {
this.dependencies = [
"webpack",
"webpack-cli",
"terser-webpack-plugin",
"uglifyjs-webpack-plugin",
"babel-plugin-syntax-dynamic-import",
];
this.configuration = {
Expand Down Expand Up @@ -430,12 +430,12 @@ export default class InitGenerator extends Generator {
public installPlugins() {
if (this.isProd) {
this.dependencies = this.dependencies.filter(
(p: string) => p !== "terser-webpack-plugin",
(p: string) => p !== "uglifyjs-webpack-plugin",
);
} else {
this.configuration.config.topScope.push(
tooltip.terser(),
"const TerserPlugin = require('terser-webpack-plugin');",
tooltip.uglify(),
"const UglifyJSPlugin = require('uglifyjs-webpack-plugin');",
"\n",
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/generators/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Callable function with the initial plugins
*
* @returns {Function} An function that returns an array
* that consists of the terser plugin
* that consists of the uglify plugin
*/

export default function(_?: void): string[] {
return ["new TerserPlugin()"];
return ["new UglifyJSPlugin()"];
}
6 changes: 3 additions & 3 deletions packages/generators/utils/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export default {
*/`;
},

terser: (_?: void): string => {
uglify: (_?: void): string => {
return `/*
* We've enabled TerserJSPlugin for you! This minifies your app
* We've enabled UglifyJSPlugin for you! This minifies your app
* in order to load faster and run less javascript.
*
* https://github.com/webpack-contrib/terser-webpack-plugin
* https://github.com/webpack-contrib/uglifyjs-webpack-plugin
*
*/`;
},
Expand Down
3 changes: 1 addition & 2 deletions packages/migrate/__testfixtures__/failing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const webpack = require('webpack');
const nodeEnvironment = process.env.NODE_ENV;
const _ = require("lodash");
const TerserPlugin = require('terser-webpack-plugin');

const config = {
entry: {
Expand Down Expand Up @@ -44,7 +43,7 @@ const config = {

switch (nodeEnvironment) {
case "production":
config.plugins.push(new TerserPlugin());
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
case "preproduction":
config.output.path = __dirname + "/dist";
config.plugins.push(new webpack.optimize.DedupePlugin());
Expand Down
62 changes: 25 additions & 37 deletions packages/migrate/__tests__/__snapshots__/migrate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
modules: ['node_modules']
},
plugins: [
new TerserPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports = {
modules: ['node_modules']
},
plugins: [
new TerserPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
Expand All @@ -61,18 +61,15 @@ 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$/,
use: [{
Expand All @@ -81,18 +78,15 @@ module.exports = {
include: path.join(__dirname, 'src')
}]
},
resolve: {
resolve: {
modules: ['node_modules', path.resolve('/src')],
},
plugins: [
new TerserPlugin(),
new webpack.LoaderOptionsPlugin({
debug: true,
minimize: true,
})
],
plugins: [new webpack.LoaderOptionsPlugin({
debug: true,
})],
optimization: {
minimize: true,
}
};
"
`;
Expand Down Expand Up @@ -122,7 +116,7 @@ module.exports = {
modules: ['node_modules']
},
plugins: [
new TerserPlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
Expand All @@ -133,18 +127,15 @@ 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$/,
use: [{
Expand All @@ -153,18 +144,15 @@ module.exports = {
include: path.join(__dirname, 'src')
}]
},
resolve: {
resolve: {
modules: ['node_modules', path.resolve('/src')]
},
plugins: [
new TerserPlugin(),
new webpack.LoaderOptionsPlugin({
debug: true,
minimize: true
})
]
plugins: [new webpack.LoaderOptionsPlugin({
debug: true
})],
optimization: {
minimize: true
}
};
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ module.exports = {
`;

exports[`loaderOptionsPlugin transforms correctly using "loaderOptionsPlugin-1" data 1`] = `
"const TerserPlugin = require(\\"terser-webpack-plugin\\");
module.exports = {
"module.exports = {
plugins: [
new TerserPlugin(),
new webpack.LoaderOptionsPlugin({
new webpack.optimize.UglifyJsPlugin(),
new webpack.LoaderOptionsPlugin({
foo: 'bar',
debug: true,
minimize: true
})
]
]
}
"
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
debug: true,
plugins: [
new TerserPlugin(),
new webpack.LoaderOptionsPlugin({
foo: 'bar'
})
]
debug: true,
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.LoaderOptionsPlugin({
foo: 'bar'
})
]
}
4 changes: 2 additions & 2 deletions packages/migrate/loaderOptionsPlugin/loaderOptionsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default function(j: IJSCodeshift, ast: INode): INode {
});
}

// If there is TerserPlugin, set minimize: true
if (findPluginsByName(j, ast, ["TerserPlugin"]).size()) {
// If there is UglifyJsPlugin, set minimize: true
if (findPluginsByName(j, ast, ["webpack.optimize.UglifyJsPlugin"]).size()) {
loaderOptions.minimize = true;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/migrate/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import noEmitOnErrorsPluginTransform from "./noEmitOnErrorsPlugin/noEmitOnErrors
import removeDeprecatedPluginsTransform from "./removeDeprecatedPlugins/removeDeprecatedPlugins";
import removeJsonLoaderTransform from "./removeJsonLoader/removeJsonLoader";
import resolveTransform from "./resolve/resolve";
import terserPluginTransform from "./terserPlugin/terserPlugin";
import { INode } from "./types/NodePath";
import uglifyJsPluginTransform from "./uglifyJsPlugin/uglifyJsPlugin";

interface ITransformsObject {
bannerPluginTransform: object;
Expand All @@ -24,15 +24,15 @@ interface ITransformsObject {
removeDeprecatedPluginsTransform: object;
removeJsonLoaderTransform: object;
resolveTransform: object;
terserPluginTransform: object;
uglifyJsPluginTransform: object;
}

/* tslint:disable object-literal-sort-keys */
const transformsObject: ITransformsObject = {
loadersTransform,
resolveTransform,
removeJsonLoaderTransform,
terserPluginTransform,
uglifyJsPluginTransform,
loaderOptionsPluginTransform,
bannerPluginTransform,
extractTextPluginTransform,
Expand Down
Loading

0 comments on commit 9863445

Please sign in to comment.