@umijs/bundler-webpack 4.0.0-canary.20220614.2 → 4.0.0-canary.20220620.1
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/dist/build.js +3 -1
- package/dist/config/config.js +3 -0
- package/dist/config/cssRules.js +21 -0
- package/dist/config/manifestPlugin.d.ts +1 -1
- package/dist/config/miniCSSExtractPlugin.js +4 -1
- package/dist/config/ssrPlugin.d.ts +11 -0
- package/dist/config/ssrPlugin.js +66 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +16 -0
- package/dist/plugins/ProgressPlugin.js +3 -3
- package/package.json +5 -5
package/dist/build.js
CHANGED
|
@@ -32,7 +32,9 @@ async function build(opts) {
|
|
|
32
32
|
});
|
|
33
33
|
let isFirstCompile = true;
|
|
34
34
|
return new Promise((resolve, reject) => {
|
|
35
|
-
|
|
35
|
+
if (opts.clean) {
|
|
36
|
+
utils_1.rimraf.sync(webpackConfig.output.path);
|
|
37
|
+
}
|
|
36
38
|
const compiler = (0, webpack_1.default)(webpackConfig);
|
|
37
39
|
compiler.run((err, stats) => {
|
|
38
40
|
var _a;
|
package/dist/config/config.js
CHANGED
|
@@ -28,6 +28,7 @@ const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
|
|
|
28
28
|
const nodePolyfill_1 = require("./nodePolyfill");
|
|
29
29
|
const progressPlugin_1 = require("./progressPlugin");
|
|
30
30
|
const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
|
|
31
|
+
const ssrPlugin_1 = __importDefault(require("./ssrPlugin"));
|
|
31
32
|
const svgRules_1 = require("./svgRules");
|
|
32
33
|
async function getConfig(opts) {
|
|
33
34
|
const { userConfig } = opts;
|
|
@@ -138,6 +139,8 @@ async function getConfig(opts) {
|
|
|
138
139
|
if (isDev && opts.hmr) {
|
|
139
140
|
config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
|
|
140
141
|
}
|
|
142
|
+
// ssr
|
|
143
|
+
await (0, ssrPlugin_1.default)(applyOpts);
|
|
141
144
|
// compress
|
|
142
145
|
await (0, compressPlugin_1.addCompressPlugin)(applyOpts);
|
|
143
146
|
// purgecss
|
package/dist/config/cssRules.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addCSSRules = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
4
5
|
async function addCSSRules(opts) {
|
|
5
6
|
const { config, userConfig } = opts;
|
|
6
7
|
const rulesConfig = [
|
|
@@ -71,6 +72,23 @@ async function addCSSRules(opts) {
|
|
|
71
72
|
modules: {
|
|
72
73
|
localIdentName: '[local]___[hash:base64:5]',
|
|
73
74
|
...userConfig.cssLoaderModules,
|
|
75
|
+
// If SSR is enabled, we need to handling the css modules name hashing
|
|
76
|
+
// and save the class names mapping into opts.cssModulesMapping
|
|
77
|
+
// so the esbuild can use it to generate the correct name for the server side
|
|
78
|
+
getLocalIdent: userConfig.ssr &&
|
|
79
|
+
((context, localIdentName, localName, opt) => {
|
|
80
|
+
const classIdent = ((0, utils_1.winPath)(context.resourcePath).replace((0, utils_1.winPath)(ensureLastSlash(opt.context)), '') +
|
|
81
|
+
'@' +
|
|
82
|
+
localName).trim();
|
|
83
|
+
let hash = Buffer.from(classIdent)
|
|
84
|
+
.toString('base64')
|
|
85
|
+
.replace(/=/g, '');
|
|
86
|
+
hash = hash.substring(hash.length - 5);
|
|
87
|
+
const result = localIdentName
|
|
88
|
+
.replace(/\[local]/g, localName)
|
|
89
|
+
.replace(/\[hash[^\[]*?]/g, hash);
|
|
90
|
+
return result;
|
|
91
|
+
}),
|
|
74
92
|
},
|
|
75
93
|
}
|
|
76
94
|
: {}),
|
|
@@ -106,3 +124,6 @@ async function addCSSRules(opts) {
|
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
exports.addCSSRules = addCSSRules;
|
|
127
|
+
function ensureLastSlash(path) {
|
|
128
|
+
return path.endsWith('/') ? path : path + '/';
|
|
129
|
+
}
|
|
@@ -13,7 +13,10 @@ async function addMiniCSSExtractPlugin(opts) {
|
|
|
13
13
|
config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
|
|
14
14
|
{
|
|
15
15
|
filename: `[name]${hash}.css`,
|
|
16
|
-
chunkFilename:
|
|
16
|
+
chunkFilename: opts.userConfig.ssr
|
|
17
|
+
? // TODO: FIXME
|
|
18
|
+
`umi${hash}.css`
|
|
19
|
+
: `[name]${hash}.chunk.css`,
|
|
17
20
|
ignoreOrder: true,
|
|
18
21
|
},
|
|
19
22
|
]);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Config from '../../compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
name?: string;
|
|
5
|
+
config: Config;
|
|
6
|
+
userConfig: IConfig;
|
|
7
|
+
cwd: string;
|
|
8
|
+
env: Env;
|
|
9
|
+
}
|
|
10
|
+
export default function addSSRPlugin(opts: IOpts): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const PLUGIN_NAME = 'SSR_PLUGIN';
|
|
9
|
+
class SSRPlugin {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.opts = opts;
|
|
12
|
+
this.manifest = new Map();
|
|
13
|
+
}
|
|
14
|
+
apply(compiler) {
|
|
15
|
+
// ref: https://github.com/webdeveric/webpack-assets-manifest
|
|
16
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
17
|
+
compilation.hooks.processAssets.tap(PLUGIN_NAME, () => {
|
|
18
|
+
const publicPath = compiler.options.output.publicPath || '/';
|
|
19
|
+
const assets = compilation.getAssets().filter((asset) => {
|
|
20
|
+
if (asset.info.hotModuleReplacement) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
});
|
|
25
|
+
assets.forEach((asset) => {
|
|
26
|
+
if (asset.info.sourceFilename) {
|
|
27
|
+
this.manifest.set(asset.info.sourceFilename, publicPath + asset.name);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const stats = compilation.getStats().toJson({
|
|
31
|
+
all: false,
|
|
32
|
+
assets: true,
|
|
33
|
+
cachedAssets: true,
|
|
34
|
+
cachedModules: true,
|
|
35
|
+
});
|
|
36
|
+
const { assetsByChunkName } = stats;
|
|
37
|
+
Object.keys(assetsByChunkName).forEach((chunkName) => {
|
|
38
|
+
assetsByChunkName[chunkName].forEach((filename) => {
|
|
39
|
+
const ext = (0, path_1.extname)(filename.split(/[?#]/)[0]);
|
|
40
|
+
if (!filename.includes('.hot-update.')) {
|
|
41
|
+
this.manifest.set(chunkName + ext, publicPath + filename);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
const assetsSource = JSON.stringify({
|
|
46
|
+
assets: Object.fromEntries(this.manifest),
|
|
47
|
+
}, null, 2);
|
|
48
|
+
if (process.env.NODE_ENV === 'production' ||
|
|
49
|
+
this.opts.userConfig.writeToDisk) {
|
|
50
|
+
compilation.emitAsset('build-manifest.json', new webpack_1.sources.RawSource(assetsSource, false));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const outputPath = compiler.options.output.path;
|
|
54
|
+
utils_1.fsExtra.mkdirpSync(outputPath);
|
|
55
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(outputPath, 'build-manifest.json'), assetsSource, 'utf-8');
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function addSSRPlugin(opts) {
|
|
62
|
+
if (opts.userConfig.ssr && opts.name !== constants_1.MFSU_NAME) {
|
|
63
|
+
opts.config.plugin('ssr-plugin').use(SSRPlugin, [opts]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.default = addSSRPlugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import * as parcelCSS from '@parcel/css';
|
|
1
2
|
import type webpack from '../compiled/webpack';
|
|
3
|
+
import './requireHook';
|
|
2
4
|
export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
|
|
3
5
|
export type { Compiler, Stats } from '../compiled/webpack';
|
|
4
6
|
export * from './build';
|
|
5
7
|
export * from './config/config';
|
|
6
8
|
export * from './dev';
|
|
7
9
|
export * from './schema';
|
|
10
|
+
export { parcelCSS };
|
|
8
11
|
export { webpack };
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,26 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
13
25
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
27
|
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.parcelCSS = void 0;
|
|
30
|
+
const parcelCSS = __importStar(require("@parcel/css"));
|
|
31
|
+
exports.parcelCSS = parcelCSS;
|
|
32
|
+
require("./requireHook");
|
|
17
33
|
__exportStar(require("./build"), exports);
|
|
18
34
|
__exportStar(require("./config/config"), exports);
|
|
19
35
|
__exportStar(require("./dev"), exports);
|
|
@@ -12,8 +12,9 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
apply(compiler) {
|
|
15
|
+
const prefix = this.options.name ? `[${this.options.name}]` : '[Webpack]';
|
|
15
16
|
compiler.hooks.invalid.tap(PLUGIN_NAME, () => {
|
|
16
|
-
utils_1.logger.wait(
|
|
17
|
+
utils_1.logger.wait(`${prefix} Compiling...`);
|
|
17
18
|
});
|
|
18
19
|
compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
|
|
19
20
|
const { errors, warnings } = stats.toJson({
|
|
@@ -32,8 +33,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
|
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
|
-
|
|
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 in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-webpack",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220620.1",
|
|
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",
|
|
@@ -35,10 +35,10 @@
|
|
|
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-canary.
|
|
39
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
40
|
-
"@umijs/mfsu": "4.0.0-canary.
|
|
41
|
-
"@umijs/utils": "4.0.0-canary.
|
|
38
|
+
"@umijs/babel-preset-umi": "4.0.0-canary.20220620.1",
|
|
39
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220620.1",
|
|
40
|
+
"@umijs/mfsu": "4.0.0-canary.20220620.1",
|
|
41
|
+
"@umijs/utils": "4.0.0-canary.20220620.1",
|
|
42
42
|
"cors": "^2.8.5",
|
|
43
43
|
"css-loader": "6.7.1",
|
|
44
44
|
"es5-imcompatible-versions": "^0.1.73",
|