@umijs/bundler-webpack 4.0.0-rc.2 → 4.0.0-rc.3
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.
- package/compiled/terser/index.js +1 -1
- package/dist/config/compressPlugin.js +6 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +74 -0
- package/dist/schema.js +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.js +1 -0
- package/package.json +8 -7
|
@@ -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
|
}
|
|
@@ -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;
|
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(),
|
package/dist/types.d.ts
CHANGED
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.
|
|
3
|
+
"version": "4.0.0-rc.3",
|
|
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,15 +28,16 @@
|
|
|
28
28
|
"generate:webpackPackages": "zx ./scripts/generateWebpackPackages.mjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@parcel/css": "1.3.2",
|
|
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.
|
|
36
|
+
"@swc/core": "1.2.143",
|
|
36
37
|
"@types/hapi__joi": "17.1.8",
|
|
37
|
-
"@umijs/babel-preset-umi": "4.0.0-rc.
|
|
38
|
-
"@umijs/mfsu": "4.0.0-rc.
|
|
39
|
-
"@umijs/utils": "4.0.0-rc.
|
|
38
|
+
"@umijs/babel-preset-umi": "4.0.0-rc.3",
|
|
39
|
+
"@umijs/mfsu": "4.0.0-rc.3",
|
|
40
|
+
"@umijs/utils": "4.0.0-rc.3",
|
|
40
41
|
"css-loader": "6.6.0",
|
|
41
42
|
"es5-imcompatible-versions": "^0.1.73",
|
|
42
43
|
"jest-worker": "27.5.1",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/express": "4.17.13",
|
|
50
51
|
"@types/webpack-sources": "3.2.0",
|
|
51
|
-
"@types/ws": "8.2.
|
|
52
|
+
"@types/ws": "8.2.3",
|
|
52
53
|
"autoprefixer": "10.4.2",
|
|
53
54
|
"babel-loader": "8.2.3",
|
|
54
55
|
"compression": "1.7.4",
|
|
@@ -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.
|
|
76
|
+
"terser": "5.11.0",
|
|
76
77
|
"terser-webpack-plugin": "5.3.1",
|
|
77
78
|
"url-loader": "4.1.1",
|
|
78
79
|
"webpack": "5.69.1",
|