From 45663be72f33574c7f38c0205aa5f92d6f2a02e0 Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Fri, 21 Jan 2022 10:09:03 -0500 Subject: [PATCH 1/2] feat: generate unminified js? Fixes #6104 (if it works) --- scripts/webpack.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/webpack.js b/scripts/webpack.js index d3a1b9fca739..7c6c9bb29a28 100644 --- a/scripts/webpack.js +++ b/scripts/webpack.js @@ -1,5 +1,6 @@ const path = require('path'); const webpack = require('webpack'); +const TerserPlugin = require("terser-webpack-plugin"); const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin'); const { flatMap } = require('lodash'); @@ -47,6 +48,9 @@ function plugins() { ignoreEsprima: () => new webpack.IgnorePlugin(/^esprima$/, /js-yaml/), ignoreMomentOptionalDeps: () => new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), friendlyErrors: () => new FriendlyErrorsWebpackPlugin(), + terser: () => new TerserPlugin({ + exclude: /unminified/, + }), }; } @@ -79,12 +83,13 @@ function targetOutputs() { return { umd: { path: umdPath, - filename: `${pkg.name}.js`, + filename: `${pkg.name}.[name].js`, library: toGlobalName(pkg.name), libraryTarget: 'umd', libraryExport: toGlobalName(pkg.name), umdNamedDefine: true, globalObject: 'window', + chunkFilename: `${pkg.name}.[name].[id].[chunkhash].js` }, umddir: { path: umdDirPath, @@ -119,7 +124,10 @@ function baseConfig({ target = isProduction ? 'umd' : 'umddir' } = {}) { return { context: process.cwd(), mode: isProduction ? 'production' : 'development', - entry: './src', + entry: { + bundle: './src', + 'bundle.unminified': './src', + }, output: targetOutputs()[target], module: { rules: flatMap(Object.values(rules()), rule => rule()), @@ -131,6 +139,9 @@ function baseConfig({ target = isProduction ? 'umd' : 'umddir' } = {}) { }, }, plugins: Object.values(plugins()).map(plugin => plugin()), + optimization: { + minimizer: [plugins().terser()], + }, devtool: isTest ? '' : 'source-map', target: 'web', From a1020f91f2f3b177ba085cbf3fc9b599664ffdcc Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Fri, 21 Jan 2022 10:33:00 -0500 Subject: [PATCH 2/2] fix: use a function --- scripts/webpack.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/webpack.js b/scripts/webpack.js index 7c6c9bb29a28..cc2d274d3508 100644 --- a/scripts/webpack.js +++ b/scripts/webpack.js @@ -83,7 +83,7 @@ function targetOutputs() { return { umd: { path: umdPath, - filename: `${pkg.name}.[name].js`, + filename: pathData => pathData.chunk.name === 'minified' ? `${pkg.name}.js` : `${pkg.name}.[name].js`, library: toGlobalName(pkg.name), libraryTarget: 'umd', libraryExport: toGlobalName(pkg.name), @@ -125,8 +125,8 @@ function baseConfig({ target = isProduction ? 'umd' : 'umddir' } = {}) { context: process.cwd(), mode: isProduction ? 'production' : 'development', entry: { - bundle: './src', - 'bundle.unminified': './src', + minified: './src', + unminified: './src', }, output: targetOutputs()[target], module: {