@umijs/bundler-webpack 4.0.0-rc.15 → 4.0.0-rc.18

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.
@@ -7,8 +7,6 @@ exports.addCompressPlugin = void 0;
7
7
  // @ts-ignore
8
8
  const css_minimizer_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/css-minimizer-webpack-plugin"));
9
9
  const terser_webpack_plugin_1 = __importDefault(require("../../compiled/terser-webpack-plugin"));
10
- const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSMinifyPlugin"));
11
- const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
12
10
  const types_1 = require("../types");
13
11
  const getEsBuildTarget_1 = require("../utils/getEsBuildTarget");
14
12
  async function addCompressPlugin(opts) {
@@ -22,24 +20,38 @@ async function addCompressPlugin(opts) {
22
20
  return;
23
21
  }
24
22
  config.optimization.minimize(true);
23
+ // esbuild transform only allow `string[]` as target
24
+ const esbuildTarget = (0, getEsBuildTarget_1.getEsBuildTarget)({
25
+ targets: userConfig.targets || {},
26
+ });
25
27
  let minify;
26
28
  let terserOptions;
27
29
  if (jsMinifier === types_1.JSMinifier.esbuild) {
28
30
  minify = terser_webpack_plugin_1.default.esbuildMinify;
29
31
  terserOptions = {
30
- target: (0, getEsBuildTarget_1.getEsBuildTarget)({
31
- targets: userConfig.targets || {},
32
- }),
32
+ target: esbuildTarget,
33
+ // remove all comments
34
+ legalComments: 'none',
33
35
  };
34
36
  }
35
37
  else if (jsMinifier === types_1.JSMinifier.terser) {
36
38
  minify = terser_webpack_plugin_1.default.terserMinify;
39
+ terserOptions = {
40
+ format: {
41
+ comments: false,
42
+ },
43
+ };
37
44
  }
38
45
  else if (jsMinifier === types_1.JSMinifier.swc) {
39
46
  minify = terser_webpack_plugin_1.default.swcMinify;
40
47
  }
41
48
  else if (jsMinifier === types_1.JSMinifier.uglifyJs) {
42
49
  minify = terser_webpack_plugin_1.default.uglifyJsMinify;
50
+ terserOptions = {
51
+ output: {
52
+ comments: false,
53
+ },
54
+ };
43
55
  }
44
56
  else if (jsMinifier !== types_1.JSMinifier.none) {
45
57
  throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
@@ -51,33 +63,40 @@ async function addCompressPlugin(opts) {
51
63
  if (jsMinifier !== types_1.JSMinifier.none) {
52
64
  config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
53
65
  {
66
+ extractComments: false,
54
67
  minify,
55
68
  terserOptions,
56
69
  },
57
70
  ]);
58
71
  }
72
+ let cssMinify;
73
+ let minimizerOptions;
59
74
  if (cssMinifier === types_1.CSSMinifier.esbuild) {
60
- config.optimization
61
- .minimizer(`css-${cssMinifier}`)
62
- .use(ESBuildCSSMinifyPlugin_1.default, [userConfig.cssMinifierOptions]);
75
+ cssMinify = css_minimizer_webpack_plugin_1.default.esbuildMinify;
76
+ minimizerOptions = {
77
+ target: esbuildTarget,
78
+ };
63
79
  }
64
80
  else if (cssMinifier === types_1.CSSMinifier.cssnano) {
65
- config.optimization
66
- .minimizer(`css-${cssMinifier}`)
67
- .use(css_minimizer_webpack_plugin_1.default, [
68
- {
69
- minimizerOptions: userConfig.cssMinifierOptions,
70
- parallel: true,
71
- },
72
- ]);
81
+ cssMinify = css_minimizer_webpack_plugin_1.default.cssnanoMinify;
73
82
  }
74
83
  else if (cssMinifier === types_1.CSSMinifier.parcelCSS) {
75
- config.optimization
76
- .minimizer(`css-${cssMinifier}`)
77
- .use(ParcelCSSMinifyPlugin_1.ParcelCSSMinifyPlugin);
84
+ cssMinify = css_minimizer_webpack_plugin_1.default.parcelCssMinify;
78
85
  }
79
86
  else if (cssMinifier !== types_1.CSSMinifier.none) {
80
87
  throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
81
88
  }
89
+ minimizerOptions = {
90
+ ...minimizerOptions,
91
+ ...userConfig.cssMinifierOptions,
92
+ };
93
+ config.optimization
94
+ .minimizer(`css-${cssMinifier}`)
95
+ .use(css_minimizer_webpack_plugin_1.default, [
96
+ {
97
+ minify: cssMinify,
98
+ minimizerOptions,
99
+ },
100
+ ]);
82
101
  }
83
102
  exports.addCompressPlugin = addCompressPlugin;
@@ -88,6 +88,9 @@ async function addJavaScriptRules(opts) {
88
88
  })
89
89
  .end(),
90
90
  ];
91
+ srcRules
92
+ .concat(depRules)
93
+ .forEach((rule) => rule.resolve.set('fullySpecified', false));
91
94
  // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
92
95
  const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
93
96
  srcRules.forEach((rule) => {
@@ -23,6 +23,7 @@ async function addSVGRules(opts) {
23
23
  },
24
24
  },
25
25
  },
26
+ 'prefixIds',
26
27
  ],
27
28
  ...svgo,
28
29
  },
@@ -11,7 +11,7 @@ class RuntimePublicPathPlugin {
11
11
  // https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
12
12
  if (module.constructor.name === 'PublicPathRuntimeModule') {
13
13
  // @ts-ignore
14
- module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath;`;
14
+ module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath || '/';`;
15
15
  }
16
16
  });
17
17
  });
package/dist/schema.js CHANGED
@@ -4,18 +4,30 @@ exports.getSchemas = void 0;
4
4
  const types_1 = require("./types");
5
5
  const options = [
6
6
  'cheap-source-map',
7
- 'cheap-eval-source-map',
8
- 'cheap-hidden-source-map',
9
- 'cheap-inline-source-map',
10
7
  'cheap-module-source-map',
11
- 'cheap-module-eval-source-map',
12
- 'cheap-module-hidden-source-map',
13
- 'cheap-module-inline-source-map',
14
8
  'eval',
15
9
  'eval-source-map',
10
+ 'eval-cheap-source-map',
11
+ 'eval-cheap-module-source-map',
12
+ 'eval-nosources-cheap-source-map',
13
+ 'eval-nosources-cheap-module-source-map',
14
+ 'eval-nosources-source-map',
16
15
  'source-map',
17
16
  'hidden-source-map',
17
+ 'hidden-nosources-cheap-source-map',
18
+ 'hidden-nosources-cheap-module-source-map',
19
+ 'hidden-nosources-source-map',
20
+ 'hidden-cheap-source-map',
21
+ 'hidden-cheap-module-source-map',
18
22
  'inline-source-map',
23
+ 'inline-cheap-source-map',
24
+ 'inline-cheap-module-source-map',
25
+ 'inline-nosources-cheap-source-map',
26
+ 'inline-nosources-cheap-module-source-map',
27
+ 'inline-nosources-source-map',
28
+ 'nosources-source-map',
29
+ 'nosources-cheap-source-map',
30
+ 'nosources-cheap-module-source-map',
19
31
  ];
20
32
  const DEVTOOL_REGEX = new RegExp('^' + // start of string
21
33
  '(#@|@|#)?' + // maybe one of the pragmas
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-rc.15",
3
+ "version": "4.0.0-rc.18",
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,22 +29,22 @@
29
29
  "test": "umi-scripts jest-turbo"
30
30
  },
31
31
  "dependencies": {
32
- "@parcel/css": "1.8.1",
32
+ "@parcel/css": "1.8.2",
33
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.15",
39
- "@umijs/bundler-utils": "4.0.0-rc.15",
40
- "@umijs/mfsu": "4.0.0-rc.15",
41
- "@umijs/utils": "4.0.0-rc.15",
38
+ "@umijs/babel-preset-umi": "4.0.0-rc.18",
39
+ "@umijs/bundler-utils": "4.0.0-rc.18",
40
+ "@umijs/mfsu": "4.0.0-rc.18",
41
+ "@umijs/utils": "4.0.0-rc.18",
42
42
  "css-loader": "6.7.1",
43
43
  "es5-imcompatible-versions": "^0.1.73",
44
44
  "jest-worker": "27.5.1",
45
45
  "node-libs-browser": "2.2.1",
46
- "postcss": "^8.4.12",
47
- "postcss-preset-env": "7.4.3",
46
+ "postcss": "^8.4.13",
47
+ "postcss-preset-env": "7.5.0",
48
48
  "react-error-overlay": "6.0.9"
49
49
  },
50
50
  "devDependencies": {
@@ -56,7 +56,7 @@
56
56
  "compression": "1.7.4",
57
57
  "connect-history-api-fallback": "1.6.0",
58
58
  "copy-webpack-plugin": "10.2.4",
59
- "css-minimizer-webpack-plugin": "3.4.1",
59
+ "css-minimizer-webpack-plugin": "4.0.0",
60
60
  "cssnano": "5.1.7",
61
61
  "fork-ts-checker-webpack-plugin": "7.2.4",
62
62
  "http-proxy-middleware": "2.0.4",
@@ -1,11 +0,0 @@
1
- import { Compilation, Compiler } from '@umijs/bundler-webpack/compiled/webpack';
2
- interface IOpts {
3
- sourcemap?: any;
4
- }
5
- declare class ESBuildCSSMinifyPlugin {
6
- options: IOpts;
7
- constructor(options?: IOpts);
8
- apply(compiler: Compiler): void;
9
- transformAssets(compilation: Compilation): Promise<void>;
10
- }
11
- export default ESBuildCSSMinifyPlugin;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
4
- const webpack_sources_1 = require("@umijs/bundler-webpack/compiled/webpack-sources");
5
- const version = require('../../package.json');
6
- const PLUGIN_NAME = 'ESBuildCSSMinifyPlugin';
7
- const RE_CSS_FILE = /\.css(\?.*)?$/i;
8
- class ESBuildCSSMinifyPlugin {
9
- constructor(options = {}) {
10
- this.options = options;
11
- }
12
- apply(compiler) {
13
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
14
- compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => {
15
- hash.update(JSON.stringify({
16
- version,
17
- options: this.options,
18
- }));
19
- });
20
- compilation.hooks.processAssets.tapPromise({
21
- name: PLUGIN_NAME,
22
- stage: 400,
23
- additionalAssets: true,
24
- }, async () => {
25
- await this.transformAssets(compilation);
26
- });
27
- });
28
- }
29
- async transformAssets(compilation) {
30
- const { options: { devtool }, } = compilation.compiler;
31
- const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
32
- const assets = compilation.getAssets().filter((asset) => {
33
- return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
34
- });
35
- await Promise.all(assets.map(async (asset) => {
36
- const { source, map } = asset.source.sourceAndMap();
37
- const sourceAsString = source.toString();
38
- const result = await (0, esbuild_1.transform)(sourceAsString, {
39
- loader: 'css',
40
- sourcemap,
41
- sourcefile: asset.name,
42
- minify: true,
43
- });
44
- compilation.updateAsset(asset.name,
45
- // @ts-ignore
46
- sourcemap
47
- ? new webpack_sources_1.SourceMapSource(result.code, asset.name, result.map, sourceAsString, map, true)
48
- : new webpack_sources_1.RawSource(result.code), { ...asset.info, minimized: true });
49
- }));
50
- }
51
- }
52
- exports.default = ESBuildCSSMinifyPlugin;
@@ -1,10 +0,0 @@
1
- import type { TransformOptions } from '@parcel/css';
2
- import type { Compiler } from '../../compiled/webpack/types';
3
- declare type MinifyPluginOpts = Omit<TransformOptions, 'filename' | 'code' | 'minify'>;
4
- export declare class ParcelCSSMinifyPlugin {
5
- private readonly options;
6
- constructor(opts?: MinifyPluginOpts);
7
- apply(compiler: Compiler): void;
8
- private transformAssets;
9
- }
10
- export {};
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParcelCSSMinifyPlugin = void 0;
4
- const utils_1 = require("@umijs/utils");
5
- const buffer_1 = require("buffer");
6
- const path_1 = require("path");
7
- const webpack_sources_1 = require("../../compiled/webpack-sources");
8
- const pkgPath = (0, path_1.join)(__dirname, '../../package.json');
9
- const pkg = require(pkgPath);
10
- const PLUGIN_NAME = 'parcel-css-minify-plugin';
11
- const CSS_FILE_REG = /\.css(?:\?.*)?$/i;
12
- class ParcelCSSMinifyPlugin {
13
- constructor(opts = {}) {
14
- this.options = opts;
15
- }
16
- apply(compiler) {
17
- const meta = JSON.stringify({
18
- name: pkg.name,
19
- version: pkg.version,
20
- options: this.options,
21
- });
22
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
23
- compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
24
- compilation.hooks.processAssets.tapPromise({
25
- name: PLUGIN_NAME,
26
- // @ts-ignore
27
- stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
28
- additionalAssets: true,
29
- }, async () => await this.transformAssets(compilation));
30
- compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
31
- statsPrinter.hooks.print
32
- .for('asset.info.minimized')
33
- // @ts-ignore
34
- .tap(PLUGIN_NAME, (minimized, { green, formatFlag }) => {
35
- // @ts-ignore
36
- return minimized ? green(formatFlag('minimized')) : undefined;
37
- });
38
- });
39
- });
40
- }
41
- async transformAssets(compilation) {
42
- const { options: { devtool }, } = compilation.compiler;
43
- const sourcemap = this.options.sourceMap === undefined
44
- ? (devtool && devtool.includes('source-map'))
45
- : this.options.sourceMap;
46
- const assets = compilation.getAssets().filter((asset) => {
47
- return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
48
- });
49
- await Promise.all(assets.map(async (asset) => {
50
- const { source, map } = asset.source.sourceAndMap();
51
- const sourceAsString = source.toString();
52
- const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
53
- const { transform } = (0, utils_1.importLazy)('@parcel/css');
54
- const result = await transform({
55
- filename: asset.name,
56
- code,
57
- minify: true,
58
- sourceMap: sourcemap,
59
- ...this.options,
60
- });
61
- const codeString = result.code.toString();
62
- compilation.updateAsset(asset.name,
63
- // @ts-ignore
64
- sourcemap
65
- ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
66
- : new webpack_sources_1.RawSource(codeString), {
67
- ...asset.info,
68
- minimized: true,
69
- });
70
- }));
71
- }
72
- }
73
- exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;