diff --git a/package.json b/package.json index f21de0082..e2a714ce6 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,8 @@ "web-ext": "2.7.0", "webpack": "4.14.0", "webpack-bundle-analyzer": "2.13.1", - "webpack-cli": "3.0.8" + "webpack-cli": "3.0.8", + "webpack-merge": "4.1.3" }, "dependencies": { "choo": "6.12.1", diff --git a/webpack.config.js b/webpack.config.js index 611435da5..7081dc1c2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,8 @@ const path = require('path') const webpack = require('webpack') +const merge = require('webpack-merge') const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin') +const UglifyJsPlugin = require('uglifyjs-webpack-plugin') // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // common configuration shared by all targets @@ -12,6 +14,19 @@ const commonConfig = { publicPath: '/dist/bundles/', filename: '[name].bundle.js' }, + optimization: { + minimizer: [ + // Default flags breaks js-ipfs: https://github.com/ipfs-shipyard/ipfs-companion/issues/521 + new UglifyJsPlugin({ + parallel: true, + extractComments: true, + uglifyOptions: { + compress: { unused: false }, + mangle: true + } + }) + ] + }, // plugins: [new BundleAnalyzerPlugin()] plugins: [ new SimpleProgressWebpackPlugin({ @@ -47,7 +62,7 @@ const commonConfig = { } // background page bundle (with heavy dependencies) -const bgConfig = Object.assign({}, commonConfig, { +const bgConfig = merge(commonConfig, { name: 'background', entry: { backgroundPage: './add-on/src/background/background.js' @@ -71,7 +86,7 @@ const bgConfig = Object.assign({}, commonConfig, { }) // user interface pages with shared common libraries -const uiConfig = Object.assign({}, commonConfig, { +const uiConfig = merge(commonConfig, { name: 'ui', entry: { browserAction: './add-on/src/popup/browser-action/index.js', @@ -100,7 +115,7 @@ const uiConfig = Object.assign({}, commonConfig, { }) // content scripts injected into tabs -const contentScriptsConfig = Object.assign({}, commonConfig, { +const contentScriptsConfig = merge(commonConfig, { name: 'contentScripts', entry: { ipfsProxyContentScriptPayload: './add-on/src/contentScripts/ipfs-proxy/page.js', @@ -111,7 +126,7 @@ const contentScriptsConfig = Object.assign({}, commonConfig, { // special content script that injects window.ipfs into REAL window object // (by default scripts executed via tabs.executeScript get a sandbox version) -const proxyContentScriptConfig = Object.assign({}, commonConfig, { +const proxyContentScriptConfig = merge(commonConfig, { name: 'proxyContentScript', dependencies: ['contentScripts'], entry: { diff --git a/yarn.lock b/yarn.lock index f4af878b7..6e0ff0ce4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10726,6 +10726,12 @@ webpack-cli@3.0.8: v8-compile-cache "^2.0.0" yargs "^11.1.0" +webpack-merge@4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.3.tgz#8aaff2108a19c29849bc9ad2a7fd7fce68e87c4a" + dependencies: + lodash "^4.17.5" + webpack-sources@^1.0.1, webpack-sources@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.1.0.tgz#a101ebae59d6507354d71d8013950a3a8b7a5a54"