Skip to content

Commit

Permalink
Merge 4834c50 into df28049
Browse files Browse the repository at this point in the history
  • Loading branch information
homer0 committed Apr 24, 2019
2 parents df28049 + 4834c50 commit a696611
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 81 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
"author": "Leonardo Apiwan (@homer0) <me@homer0.com>",
"license": "MIT",
"dependencies": {
"projext": "^6.0.2",
"projext": "^6.0.3",
"wootils": "^2.2.3",
"jimple": "1.5.0",
"fs-extra": "7.0.1",
"extend": "3.0.2",

"webpack": "4.30.0",
"webpack-cli": "3.3.0",
"webpack-cli": "3.3.1",
"webpack-dev-server": "3.3.1",
"mini-css-extract-plugin": "0.6.0",
"html-webpack-plugin": "3.2.0",
"script-ext-html-webpack-plugin": "2.1.3",
"compression-webpack-plugin": "2.0.0",
"uglifyjs-webpack-plugin": "2.1.2",
"terser-webpack-plugin": "1.2.3",
"optimize-css-assets-webpack-plugin": "5.0.1",
"copy-webpack-plugin": "5.0.2",
"copy-webpack-plugin": "5.0.3",

"@babel/core": "7.4.3",
"node-sass": "4.11.0",
Expand All @@ -46,7 +46,7 @@
"devDependencies": {
"eslint": "5.16.0",
"eslint-config-airbnb-base": "13.1.0",
"eslint-plugin-import": "2.17.1",
"eslint-plugin-import": "2.17.2",
"eslint-plugin-node": "8.0.1",
"@babel/preset-env": "7.4.3",
"jest-ex": "^6.0.1",
Expand Down
25 changes: 12 additions & 13 deletions src/services/configurations/browserProductionConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { DefinePlugin } = require('webpack');
Expand Down Expand Up @@ -86,12 +86,21 @@ class WebpackBrowserProductionConfiguration extends ConfigurationFile {
if (target.sourceMap.production) {
config.devtool = 'source-map';
}
// If the code won't be uglified, remove the optimization flag.
if (!target.uglifyOnProduction) {
// Enable or not uglification for the target bundle.
if (target.uglifyOnProduction) {
config.optimization = {
minimizer: [
new TerserPlugin({
sourceMap: !!target.sourceMap.production,
}),
],
};
} else {
config.optimization = {
minimize: false,
};
}

// Setup the plugins.
config.plugins = [
// If the target is a library, it doesn't need HTML on production.
Expand All @@ -112,16 +121,6 @@ class WebpackBrowserProductionConfiguration extends ConfigurationFile {
),
// To add the _'browser env variables'_.
new DefinePlugin(definitions),
// Uglify the code if necessary.
...(
target.uglifyOnProduction ?
[
new UglifyJSPlugin({
sourceMap: !!target.sourceMap.production,
}),
] :
[]
),
// To optimize the SCSS and remove repeated declarations.
new OptimizeCssAssetsPlugin(),
// To compress the emitted assets using gzip, if the target is not a library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jest.mock('mini-css-extract-plugin', () => MiniCssExtractPluginMock);
jest.mock('html-webpack-plugin');
jest.mock('script-ext-html-webpack-plugin');
jest.mock('compression-webpack-plugin');
jest.mock('uglifyjs-webpack-plugin');
jest.mock('terser-webpack-plugin');
jest.mock('optimize-css-assets-webpack-plugin');
jest.mock('copy-webpack-plugin');
jest.mock('webpack');
Expand All @@ -20,7 +20,7 @@ require('jasmine-expect');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

Expand All @@ -37,7 +37,7 @@ describe('services/configurations:browserProductionConfiguration', () => {
HtmlWebpackPlugin.mockReset();
ScriptExtHtmlWebpackPlugin.mockReset();
OptimizeCssAssetsPlugin.mockReset();
UglifyJSPlugin.mockReset();
TerserPlugin.mockReset();
CompressionPlugin.mockReset();
CopyWebpackPlugin.mockReset();
});
Expand Down Expand Up @@ -126,6 +126,9 @@ describe('services/configurations:browserProductionConfiguration', () => {
publicPath: '/',
},
mode: 'production',
optimization: {
minimizer: expect.any(Array),
},
plugins: expect.any(Array),
};
let sut = null;
Expand Down Expand Up @@ -158,8 +161,8 @@ describe('services/configurations:browserProductionConfiguration', () => {
});
expect(webpackMock.DefinePluginMock).toHaveBeenCalledTimes(1);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledWith(definitions);
expect(UglifyJSPlugin).toHaveBeenCalledTimes(1);
expect(UglifyJSPlugin).toHaveBeenCalledWith({
expect(TerserPlugin).toHaveBeenCalledTimes(1);
expect(TerserPlugin).toHaveBeenCalledWith({
sourceMap: false,
});
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -268,7 +271,7 @@ describe('services/configurations:browserProductionConfiguration', () => {
});
expect(webpackMock.DefinePluginMock).toHaveBeenCalledTimes(1);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledWith(definitions);
expect(UglifyJSPlugin).toHaveBeenCalledTimes(0);
expect(TerserPlugin).toHaveBeenCalledTimes(0);
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
expect(CopyWebpackPlugin).toHaveBeenCalledTimes(1);
expect(CopyWebpackPlugin).toHaveBeenCalledWith(copy);
Expand Down Expand Up @@ -340,6 +343,9 @@ describe('services/configurations:browserProductionConfiguration', () => {
publicPath: '/',
},
mode: 'production',
optimization: {
minimizer: expect.any(Array),
},
plugins: expect.any(Array),
watch: target.watch.production,
};
Expand Down Expand Up @@ -373,8 +379,8 @@ describe('services/configurations:browserProductionConfiguration', () => {
});
expect(webpackMock.DefinePluginMock).toHaveBeenCalledTimes(1);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledWith(definitions);
expect(UglifyJSPlugin).toHaveBeenCalledTimes(1);
expect(UglifyJSPlugin).toHaveBeenCalledWith({
expect(TerserPlugin).toHaveBeenCalledTimes(1);
expect(TerserPlugin).toHaveBeenCalledWith({
sourceMap: false,
});
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -450,6 +456,9 @@ describe('services/configurations:browserProductionConfiguration', () => {
publicPath: '/',
},
mode: 'production',
optimization: {
minimizer: expect.any(Array),
},
plugins: expect.any(Array),
};
let sut = null;
Expand Down Expand Up @@ -479,8 +488,8 @@ describe('services/configurations:browserProductionConfiguration', () => {
});
expect(webpackMock.DefinePluginMock).toHaveBeenCalledTimes(1);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledWith(definitions);
expect(UglifyJSPlugin).toHaveBeenCalledTimes(1);
expect(UglifyJSPlugin).toHaveBeenCalledWith({
expect(TerserPlugin).toHaveBeenCalledTimes(1);
expect(TerserPlugin).toHaveBeenCalledWith({
sourceMap: false,
});
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -557,6 +566,9 @@ describe('services/configurations:browserProductionConfiguration', () => {
publicPath: '/',
},
mode: 'production',
optimization: {
minimizer: expect.any(Array),
},
plugins: expect.any(Array),
};
let sut = null;
Expand Down Expand Up @@ -589,8 +601,8 @@ describe('services/configurations:browserProductionConfiguration', () => {
});
expect(webpackMock.DefinePluginMock).toHaveBeenCalledTimes(1);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledWith(definitions);
expect(UglifyJSPlugin).toHaveBeenCalledTimes(1);
expect(UglifyJSPlugin).toHaveBeenCalledWith({
expect(TerserPlugin).toHaveBeenCalledTimes(1);
expect(TerserPlugin).toHaveBeenCalledWith({
sourceMap: true,
});
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -664,6 +676,9 @@ describe('services/configurations:browserProductionConfiguration', () => {
publicPath: '/',
},
mode: 'production',
optimization: {
minimizer: expect.any(Array),
},
plugins: expect.any(Array),
};
let sut = null;
Expand All @@ -686,8 +701,8 @@ describe('services/configurations:browserProductionConfiguration', () => {
expect(ScriptExtHtmlWebpackPlugin).toHaveBeenCalledTimes(0);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledTimes(1);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledWith(definitions);
expect(UglifyJSPlugin).toHaveBeenCalledTimes(1);
expect(UglifyJSPlugin).toHaveBeenCalledWith({
expect(TerserPlugin).toHaveBeenCalledTimes(1);
expect(TerserPlugin).toHaveBeenCalledWith({
sourceMap: false,
});
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -761,6 +776,9 @@ describe('services/configurations:browserProductionConfiguration', () => {
publicPath: '/',
},
mode: 'production',
optimization: {
minimizer: expect.any(Array),
},
plugins: expect.any(Array),
};
let sut = null;
Expand All @@ -783,8 +801,8 @@ describe('services/configurations:browserProductionConfiguration', () => {
expect(ScriptExtHtmlWebpackPlugin).toHaveBeenCalledTimes(0);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledTimes(1);
expect(webpackMock.DefinePluginMock).toHaveBeenCalledWith(definitions);
expect(UglifyJSPlugin).toHaveBeenCalledTimes(1);
expect(UglifyJSPlugin).toHaveBeenCalledWith({
expect(TerserPlugin).toHaveBeenCalledTimes(1);
expect(TerserPlugin).toHaveBeenCalledWith({
sourceMap: false,
});
expect(OptimizeCssAssetsPlugin).toHaveBeenCalledTimes(1);
Expand Down
Loading

0 comments on commit a696611

Please sign in to comment.