@umijs/bundler-webpack 4.0.0-rc.2 → 4.0.0-rc.5

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.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -17,6 +17,7 @@ exports.addCompressPlugin = void 0;
17
17
  const css_minimizer_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/css-minimizer-webpack-plugin"));
18
18
  const terser_webpack_plugin_1 = __importDefault(require("../../compiled/terser-webpack-plugin"));
19
19
  const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSMinifyPlugin"));
20
+ const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
20
21
  const types_1 = require("../types");
21
22
  function addCompressPlugin(opts) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -69,6 +70,11 @@ function addCompressPlugin(opts) {
69
70
  },
70
71
  ]);
71
72
  }
73
+ else if (cssMinifier === types_1.CSSMinifier.parcelCSS) {
74
+ config.optimization
75
+ .minimizer(`css-${cssMinifier}`)
76
+ .use(ParcelCSSMinifyPlugin_1.ParcelCSSMinifyPlugin);
77
+ }
72
78
  else if (cssMinifier !== types_1.CSSMinifier.none) {
73
79
  throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
74
80
  }
@@ -114,7 +114,7 @@ const logUnusedFiles = (unusedFiles) => {
114
114
  if (!(unusedFiles === null || unusedFiles === void 0 ? void 0 : unusedFiles.length)) {
115
115
  return;
116
116
  }
117
- console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${unusedFiles.length} unused files:\n`), ...unusedFiles.map((file, index) => `${index + 1}. ${utils_1.chalk.yellow(file)}\n`), utils_1.chalk.red.bold('Please be careful if you want to remove them (¬º-°)¬.\n'));
117
+ console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${unusedFiles.length} unused files:`), ...unusedFiles.map((file, index) => `\n${index + 1}. ${utils_1.chalk.yellow(file)}`), utils_1.chalk.red.bold('\nPlease be careful if you want to remove them (¬º-°)¬.\n'));
118
118
  };
119
119
  const convertToUnixPath = (path) => path.replace(/\\+/g, '/');
120
120
  exports.default = detectDeadCode;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -8,16 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.addJavaScriptRules = void 0;
16
13
  const mfsu_1 = require("@umijs/mfsu");
17
14
  const utils_1 = require("@umijs/utils");
18
15
  const webpack_1 = require("../../compiled/webpack");
19
16
  const constants_1 = require("../constants");
20
- const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
21
17
  const types_1 = require("../types");
22
18
  const depMatch_1 = require("../utils/depMatch");
23
19
  function addJavaScriptRules(opts) {
@@ -118,11 +114,12 @@ function addJavaScriptRules(opts) {
118
114
  });
119
115
  }
120
116
  else if (srcTranspiler === types_1.Transpiler.swc) {
117
+ const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
121
118
  rule
122
119
  .use('swc-loader')
123
120
  .loader(require.resolve('../loader/swc'))
124
121
  .options({
125
- plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
122
+ plugin: (m) => new AutoCSSModule().visitProgram(m),
126
123
  });
127
124
  }
128
125
  else if (srcTranspiler === types_1.Transpiler.esbuild) {
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -0,0 +1,10 @@
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 {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ParcelCSSMinifyPlugin = void 0;
13
+ const css_1 = require("@parcel/css");
14
+ const buffer_1 = require("buffer");
15
+ const path_1 = require("path");
16
+ const webpack_sources_1 = require("../../compiled/webpack-sources");
17
+ const pkgPath = (0, path_1.join)(__dirname, '../../package.json');
18
+ const pkg = require(pkgPath);
19
+ const PLUGIN_NAME = 'parcel-css-minify-plugin';
20
+ const CSS_FILE_REG = /\.css(?:\?.*)?$/i;
21
+ class ParcelCSSMinifyPlugin {
22
+ constructor(opts = {}) {
23
+ this.options = opts;
24
+ }
25
+ apply(compiler) {
26
+ const meta = JSON.stringify({
27
+ name: pkg.name,
28
+ version: pkg.version,
29
+ options: this.options,
30
+ });
31
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
32
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
33
+ compilation.hooks.processAssets.tapPromise({
34
+ name: PLUGIN_NAME,
35
+ // @ts-ignore
36
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
37
+ additionalAssets: true,
38
+ }, () => __awaiter(this, void 0, void 0, function* () { return yield this.transformAssets(compilation); }));
39
+ compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
40
+ statsPrinter.hooks.print
41
+ .for('asset.info.minimized')
42
+ // @ts-ignore
43
+ .tap(PLUGIN_NAME, (minimized, { green, formatFlag }) => {
44
+ // @ts-ignore
45
+ return minimized ? green(formatFlag('minimized')) : undefined;
46
+ });
47
+ });
48
+ });
49
+ }
50
+ transformAssets(compilation) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const { options: { devtool }, } = compilation.compiler;
53
+ const sourcemap = this.options.sourceMap === undefined
54
+ ? (devtool && devtool.includes('source-map'))
55
+ : this.options.sourceMap;
56
+ const assets = compilation.getAssets().filter((asset) => {
57
+ return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
58
+ });
59
+ yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
60
+ const { source, map } = asset.source.sourceAndMap();
61
+ const sourceAsString = source.toString();
62
+ const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
63
+ const result = yield (0, css_1.transform)(Object.assign({ filename: asset.name, code, minify: true, sourceMap: sourcemap }, this.options));
64
+ const codeString = result.code.toString();
65
+ compilation.updateAsset(asset.name,
66
+ // @ts-ignore
67
+ sourcemap
68
+ ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
69
+ : new webpack_sources_1.RawSource(codeString), Object.assign(Object.assign({}, asset.info), { minimized: true }));
70
+ })));
71
+ });
72
+ }
73
+ }
74
+ exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;
@@ -13,7 +13,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
13
13
  }
14
14
  apply(compiler) {
15
15
  compiler.hooks.invalid.tap(PLUGIN_NAME, () => {
16
- utils_1.logger.wait('compiling...');
16
+ utils_1.logger.wait('Compiling...');
17
17
  });
18
18
  compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
19
19
  const { errors, warnings } = stats.toJson({
@@ -33,7 +33,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
33
33
  }
34
34
  else {
35
35
  const prefix = this.options.name ? `${this.options.name} ` : '';
36
- utils_1.logger.event(`${prefix}compiled successfully in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
36
+ utils_1.logger.event(`${prefix}Compiled successfully in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
37
37
  }
38
38
  });
39
39
  }
package/dist/schema.js CHANGED
@@ -32,7 +32,7 @@ function getSchemas() {
32
32
  }), Joi.string())),
33
33
  cssLoader: (Joi) => Joi.object(),
34
34
  cssLoaderModules: (Joi) => Joi.object(),
35
- cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.none),
35
+ cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.parcelCSS, types_1.CSSMinifier.none),
36
36
  cssMinifierOptions: (Joi) => Joi.object(),
37
37
  define: (Joi) => Joi.object(),
38
38
  deadCode: (Joi) => Joi.object(),
@@ -1,4 +1,4 @@
1
- import { ImportDeclaration } from '@swc/core';
1
+ import type { ImportDeclaration } from '@swc/core';
2
2
  import Visitor from '@swc/core/Visitor';
3
3
  declare class LockCoreJS extends Visitor {
4
4
  visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
package/dist/types.d.ts CHANGED
@@ -22,6 +22,7 @@ export declare enum JSMinifier {
22
22
  export declare enum CSSMinifier {
23
23
  esbuild = "esbuild",
24
24
  cssnano = "cssnano",
25
+ parcelCSS = "parcelCSS",
25
26
  none = "none"
26
27
  }
27
28
  export interface ICopy {
package/dist/types.js CHANGED
@@ -25,5 +25,6 @@ var CSSMinifier;
25
25
  (function (CSSMinifier) {
26
26
  CSSMinifier["esbuild"] = "esbuild";
27
27
  CSSMinifier["cssnano"] = "cssnano";
28
+ CSSMinifier["parcelCSS"] = "parcelCSS";
28
29
  CSSMinifier["none"] = "none";
29
30
  })(CSSMinifier = exports.CSSMinifier || (exports.CSSMinifier = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-rc.2",
3
+ "version": "4.0.0-rc.5",
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",
@@ -28,34 +28,35 @@
28
28
  "generate:webpackPackages": "zx ./scripts/generateWebpackPackages.mjs"
29
29
  },
30
30
  "dependencies": {
31
+ "@parcel/css": "1.5.0",
31
32
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
32
33
  "@svgr/core": "6.2.1",
33
34
  "@svgr/plugin-jsx": "^6.2.1",
34
35
  "@svgr/plugin-svgo": "^6.2.0",
35
- "@swc/core": "1.2.141",
36
36
  "@types/hapi__joi": "17.1.8",
37
- "@umijs/babel-preset-umi": "4.0.0-rc.2",
38
- "@umijs/mfsu": "4.0.0-rc.2",
39
- "@umijs/utils": "4.0.0-rc.2",
37
+ "@umijs/babel-preset-umi": "4.0.0-rc.5",
38
+ "@umijs/mfsu": "4.0.0-rc.5",
39
+ "@umijs/utils": "4.0.0-rc.5",
40
40
  "css-loader": "6.6.0",
41
41
  "es5-imcompatible-versions": "^0.1.73",
42
42
  "jest-worker": "27.5.1",
43
43
  "node-libs-browser": "2.2.1",
44
- "postcss": "^8.4.6",
45
- "postcss-preset-env": "7.4.1",
44
+ "postcss": "^8.4.7",
45
+ "postcss-preset-env": "7.4.2",
46
46
  "react-error-overlay": "6.0.9"
47
47
  },
48
48
  "devDependencies": {
49
+ "@swc/core": "1.2.147",
49
50
  "@types/express": "4.17.13",
50
51
  "@types/webpack-sources": "3.2.0",
51
- "@types/ws": "8.2.2",
52
+ "@types/ws": "8.5.2",
52
53
  "autoprefixer": "10.4.2",
53
54
  "babel-loader": "8.2.3",
54
55
  "compression": "1.7.4",
55
56
  "connect-history-api-fallback": "1.6.0",
56
57
  "copy-webpack-plugin": "10.2.4",
57
58
  "css-minimizer-webpack-plugin": "3.4.1",
58
- "cssnano": "5.0.17",
59
+ "cssnano": "5.1.0",
59
60
  "express": "4.17.3",
60
61
  "fork-ts-checker-webpack-plugin": "7.2.1",
61
62
  "http-proxy-middleware": "2.0.3",
@@ -72,7 +73,7 @@
72
73
  "style-loader": "3.3.1",
73
74
  "svgo-loader": "3.0.0",
74
75
  "tapable": "2.2.1",
75
- "terser": "5.10.0",
76
+ "terser": "5.12.0",
76
77
  "terser-webpack-plugin": "5.3.1",
77
78
  "url-loader": "4.1.1",
78
79
  "webpack": "5.69.1",