diff --git a/invenio_assets/assets/build/webpack.config.js b/invenio_assets/assets/build/webpack.config.js index 25ddbf4..f1068da 100644 --- a/invenio_assets/assets/build/webpack.config.js +++ b/invenio_assets/assets/build/webpack.config.js @@ -10,7 +10,6 @@ */ const BundleTracker = require("webpack-bundle-tracker"); -const { CleanWebpackPlugin } = require("clean-webpack-plugin"); const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); const ESLintPlugin = require("eslint-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); @@ -19,7 +18,7 @@ const TerserPlugin = require("terser-webpack-plugin"); const config = require("./config"); const path = require("path"); const webpack = require("webpack"); - +const devMode = process.env.NODE_ENV !== "production"; // Load aliases from config and resolve their full path let aliases = {}; if (config.aliases) { @@ -61,42 +60,17 @@ var webpackConfig = { filename: "js/[name].[chunkhash].js", chunkFilename: "js/[id].[chunkhash].js", publicPath: config.build.assetsURL, + clean: true, }, optimization: { + minimize: true, minimizer: [ new TerserPlugin({ terserOptions: { - parse: { - // We want terser to parse ecma 8 code. However, we don't want it - // to apply any minification steps that turns valid ecma 5 code - // into invalid ecma 5 code. This is why the 'compress' and 'output' - // sections only apply transformations that are ecma 5 safe - // https://github.com/facebook/create-react-app/pull/4234 - ecma: 8, - }, - compress: { - ecma: 5, - warnings: false, - // Disabled because of an issue with Uglify breaking seemingly valid code: - // https://github.com/facebook/create-react-app/issues/2376 - // Pending further investigation: - // https://github.com/mishoo/UglifyJS2/issues/2011 - comparisons: false, - // Disabled because of an issue with Terser breaking valid code: - // https://github.com/facebook/create-react-app/issues/5250 - // Pending further investigation: - // https://github.com/terser-js/terser/issues/120 - inline: 2, - }, - mangle: { - safari10: true, - }, + compress: true, + mangle: true, output: { - ecma: 5, comments: false, - // Turned on because emoji and regex is not minified properly using default - // https://github.com/facebook/create-react-app/issues/2488 - ascii_only: true, }, }, }), @@ -189,8 +163,7 @@ var webpackConfig = { }, ], }, - devtool: - process.env.NODE_ENV === "production" ? "source-map" : "inline-source-map", + devtool: devMode ? "inline-source-map" : "source-map", plugins: [ new ESLintPlugin({ emitWarning: true, @@ -208,13 +181,6 @@ var webpackConfig = { filename: "css/[name].[contenthash].css", chunkFilename: "css/[name].[contenthash].css", }), - // Removes the dist folder before each run. - new CleanWebpackPlugin({ - dry: false, - verbose: false, - dangerouslyAllowCleanPatternsOutsideProject: true, - cleanStaleWebpackAssets: process.env.NODE_ENV === "production", // keep stale assets in dev because of OS issues - }), // Copying relevant CSS files as TinyMCE tries to import css files from the dist/js folder of static files new CopyWebpackPlugin({ patterns: [ @@ -250,9 +216,10 @@ var webpackConfig = { snapshot: { managedPaths: [], }, + watch: devMode, watchOptions: { followSymlinks: true, - }, + }, cache: false, }; @@ -262,9 +229,5 @@ if (process.env.npm_config_report) { webpackConfig.plugins.push(new BundleAnalyzerPlugin()); } -if (process.env.NODE_ENV === "development") { - const LiveReloadPlugin = require("webpack-livereload-plugin"); - webpackConfig.plugins.push(new LiveReloadPlugin()); -} module.exports = webpackConfig; diff --git a/invenio_assets/assets/package.json b/invenio_assets/assets/package.json index 71b5138..b41556f 100644 --- a/invenio_assets/assets/package.json +++ b/invenio_assets/assets/package.json @@ -31,7 +31,6 @@ "autoprefixer": "^10.4.0", "babel-loader": "^9.0.0", "chalk": "^5.0.0", - "clean-webpack-plugin": "^4.0.0", "css-loader": "^6.0.0", "css-minimizer-webpack-plugin": "^4.2.0", "eslint-config-react-app": "^7.0.1",