@umijs/bundler-webpack 4.0.0-rc.11 → 4.0.0-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ const terser_webpack_plugin_1 = __importDefault(require("../../compiled/terser-w
19
19
  const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSMinifyPlugin"));
20
20
  const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
21
21
  const types_1 = require("../types");
22
+ const getEsBuildTarget_1 = require("../utils/getEsBuildTarget");
22
23
  function addCompressPlugin(opts) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
25
  const { config, userConfig, env } = opts;
@@ -32,8 +33,14 @@ function addCompressPlugin(opts) {
32
33
  }
33
34
  config.optimization.minimize(true);
34
35
  let minify;
36
+ let terserOptions;
35
37
  if (jsMinifier === types_1.JSMinifier.esbuild) {
36
38
  minify = terser_webpack_plugin_1.default.esbuildMinify;
39
+ terserOptions = {
40
+ target: (0, getEsBuildTarget_1.getEsBuildTarget)({
41
+ targets: userConfig.targets || {},
42
+ }),
43
+ };
37
44
  }
38
45
  else if (jsMinifier === types_1.JSMinifier.terser) {
39
46
  minify = terser_webpack_plugin_1.default.terserMinify;
@@ -47,11 +54,12 @@ function addCompressPlugin(opts) {
47
54
  else if (jsMinifier !== types_1.JSMinifier.none) {
48
55
  throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
49
56
  }
57
+ terserOptions = Object.assign(Object.assign({}, terserOptions), userConfig.jsMinifierOptions);
50
58
  if (jsMinifier !== types_1.JSMinifier.none) {
51
59
  config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
52
60
  {
53
61
  minify,
54
- terserOptions: userConfig.jsMinifierOptions,
62
+ terserOptions,
55
63
  },
56
64
  ]);
57
65
  }
@@ -12,3 +12,4 @@ export declare enum MESSAGE_TYPE {
12
12
  export declare const DEFAULT_BROWSER_TARGETS: {
13
13
  chrome: number;
14
14
  };
15
+ export declare const DEFAULT_ESBUILD_TARGET_KEYS: string[];
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
3
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
4
4
  exports.DEFAULT_DEVTOOL = 'cheap-module-source-map';
5
5
  exports.DEFAULT_OUTPUT_PATH = 'dist';
6
6
  exports.MFSU_NAME = 'MFSU';
@@ -16,3 +16,9 @@ var MESSAGE_TYPE;
16
16
  exports.DEFAULT_BROWSER_TARGETS = {
17
17
  chrome: 80,
18
18
  };
19
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = [
20
+ 'chrome',
21
+ 'firefox',
22
+ 'edge',
23
+ 'safari',
24
+ ];
package/dist/dev.d.ts CHANGED
@@ -4,6 +4,8 @@ declare type IOpts = {
4
4
  afterMiddlewares?: any[];
5
5
  beforeMiddlewares?: any[];
6
6
  onDevCompileDone?: Function;
7
+ onProgress?: Function;
8
+ onMFSUProgress?: Function;
7
9
  port?: number;
8
10
  host?: string;
9
11
  babelPreset?: any;
@@ -17,5 +19,6 @@ declare type IOpts = {
17
19
  config: IConfig;
18
20
  entry: Record<string, string>;
19
21
  } & Pick<IConfigOpts, 'cache'>;
22
+ export declare function stripUndefined(obj: any): any;
20
23
  export declare function dev(opts: IOpts): Promise<void>;
21
24
  export {};
package/dist/dev.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.dev = void 0;
15
+ exports.dev = exports.stripUndefined = void 0;
16
16
  const mfsu_1 = require("@umijs/mfsu");
17
17
  const utils_1 = require("@umijs/utils");
18
18
  const path_1 = require("path");
@@ -21,6 +21,15 @@ const config_1 = require("./config/config");
21
21
  const constants_1 = require("./constants");
22
22
  const server_1 = require("./server/server");
23
23
  const types_1 = require("./types");
24
+ function stripUndefined(obj) {
25
+ Object.keys(obj).forEach((key) => {
26
+ if (obj[key] === undefined) {
27
+ delete obj[key];
28
+ }
29
+ });
30
+ return obj;
31
+ }
32
+ exports.stripUndefined = stripUndefined;
24
33
  function dev(opts) {
25
34
  var _a, _b, _c, _d, _e, _f;
26
35
  var _g;
@@ -41,9 +50,10 @@ function dev(opts) {
41
50
  runtimePublicPath: opts.config.runtimePublicPath,
42
51
  tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
43
52
  (0, path_1.join)(opts.cwd, 'node_modules/.cache/mfsu'),
53
+ onMFSUProgress: opts.onMFSUProgress,
44
54
  getCacheDependency() {
45
55
  var _a;
46
- return {
56
+ return stripUndefined({
47
57
  version: require('../package.json').version,
48
58
  esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
49
59
  alias: opts.config.alias,
@@ -51,7 +61,7 @@ function dev(opts) {
51
61
  theme: opts.config.theme,
52
62
  runtimePublicPath: opts.config.runtimePublicPath,
53
63
  publicPath: opts.config.publicPath,
54
- };
64
+ });
55
65
  },
56
66
  });
57
67
  }
@@ -113,6 +123,7 @@ function dev(opts) {
113
123
  host: opts.host,
114
124
  afterMiddlewares: [...(opts.afterMiddlewares || [])],
115
125
  onDevCompileDone: opts.onDevCompileDone,
126
+ onProgress: opts.onProgress,
116
127
  });
117
128
  });
118
129
  }
@@ -11,6 +11,7 @@ interface IOpts {
11
11
  beforeMiddlewares?: any[];
12
12
  afterMiddlewares?: any[];
13
13
  onDevCompileDone?: Function;
14
+ onProgress?: Function;
14
15
  }
15
16
  export declare function createServer(opts: IOpts): Promise<import("https").Server | http.Server | null>;
16
17
  export {};
@@ -63,7 +63,25 @@ function createServer(opts) {
63
63
  }
64
64
  });
65
65
  // webpack dev middleware
66
- const compiler = (0, webpack_1.default)(Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig]);
66
+ const configs = Array.isArray(webpackConfig)
67
+ ? webpackConfig
68
+ : [webpackConfig];
69
+ const progresses = [];
70
+ if (opts.onProgress) {
71
+ configs.forEach((config) => {
72
+ const progress = {
73
+ percent: 0,
74
+ status: 'waiting',
75
+ };
76
+ progresses.push(progress);
77
+ config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
78
+ progress.percent = percent;
79
+ progress.status = msg;
80
+ opts.onProgress({ progresses });
81
+ }));
82
+ });
83
+ }
84
+ const compiler = (0, webpack_1.default)(configs);
67
85
  const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
68
86
  const compilerMiddleware = webpackDevMiddleware(compiler, {
69
87
  publicPath: userConfig.publicPath || '/',
@@ -0,0 +1,5 @@
1
+ interface IOpts {
2
+ targets: Record<string, any>;
3
+ }
4
+ export declare function getEsBuildTarget({ targets }: IOpts): string[];
5
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEsBuildTarget = void 0;
4
+ const constants_1 = require("../constants");
5
+ function getEsBuildTarget({ targets }) {
6
+ return Object.keys(targets)
7
+ .filter((key) => constants_1.DEFAULT_ESBUILD_TARGET_KEYS.includes(key))
8
+ .map((key) => {
9
+ return `${key}${targets[key] === true ? '0' : targets[key]}`;
10
+ });
11
+ }
12
+ exports.getEsBuildTarget = getEsBuildTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-rc.11",
3
+ "version": "4.0.0-rc.12",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -29,16 +29,16 @@
29
29
  "test": "jest -c ../../jest.turbo.config.ts"
30
30
  },
31
31
  "dependencies": {
32
- "@parcel/css": "1.7.2",
33
- "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
32
+ "@parcel/css": "1.8.1",
33
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.5",
34
34
  "@svgr/core": "6.2.1",
35
35
  "@svgr/plugin-jsx": "^6.2.1",
36
36
  "@svgr/plugin-svgo": "^6.2.0",
37
37
  "@types/hapi__joi": "17.1.8",
38
- "@umijs/babel-preset-umi": "4.0.0-rc.11",
39
- "@umijs/bundler-utils": "4.0.0-rc.11",
40
- "@umijs/mfsu": "4.0.0-rc.11",
41
- "@umijs/utils": "4.0.0-rc.11",
38
+ "@umijs/babel-preset-umi": "4.0.0-rc.12",
39
+ "@umijs/bundler-utils": "4.0.0-rc.12",
40
+ "@umijs/mfsu": "4.0.0-rc.12",
41
+ "@umijs/utils": "4.0.0-rc.12",
42
42
  "css-loader": "6.7.1",
43
43
  "es5-imcompatible-versions": "^0.1.73",
44
44
  "jest-worker": "27.5.1",
@@ -48,7 +48,7 @@
48
48
  "react-error-overlay": "6.0.9"
49
49
  },
50
50
  "devDependencies": {
51
- "@swc/core": "1.2.160",
51
+ "@swc/core": "1.2.165",
52
52
  "@types/webpack-sources": "3.2.0",
53
53
  "@types/ws": "8.5.3",
54
54
  "autoprefixer": "10.4.4",
@@ -57,15 +57,15 @@
57
57
  "connect-history-api-fallback": "1.6.0",
58
58
  "copy-webpack-plugin": "10.2.4",
59
59
  "css-minimizer-webpack-plugin": "3.4.1",
60
- "cssnano": "5.1.5",
61
- "fork-ts-checker-webpack-plugin": "7.2.1",
60
+ "cssnano": "5.1.7",
61
+ "fork-ts-checker-webpack-plugin": "7.2.4",
62
62
  "http-proxy-middleware": "2.0.4",
63
63
  "less-loader": "10.2.0",
64
64
  "mini-css-extract-plugin": "2.6.0",
65
65
  "postcss-flexbugs-fixes": "5.0.2",
66
66
  "postcss-loader": "6.2.1",
67
67
  "purgecss-webpack-plugin": "4.1.3",
68
- "react-refresh": "0.11.0",
68
+ "react-refresh": "0.12.0",
69
69
  "sass-loader": "12.6.0",
70
70
  "schema-utils": "4.0.0",
71
71
  "speed-measure-webpack-plugin": "1.5.0",
@@ -75,7 +75,7 @@
75
75
  "terser": "5.12.1",
76
76
  "terser-webpack-plugin": "5.3.1",
77
77
  "url-loader": "4.1.1",
78
- "webpack": "5.70.0",
78
+ "webpack": "5.72.0",
79
79
  "webpack-5-chain": "8.0.0",
80
80
  "webpack-bundle-analyzer": "4.5.0",
81
81
  "webpack-dev-middleware": "5.3.1",
@@ -175,6 +175,7 @@
175
175
  "postcss-flexbugs-fixes",
176
176
  "postcss-loader",
177
177
  "purgecss-webpack-plugin",
178
+ "react-refresh",
178
179
  "sass-loader",
179
180
  "speed-measure-webpack-plugin",
180
181
  "style-loader",