@umijs/bundler-webpack 4.0.0-canary.20220429.3 → 4.0.0-canary.20220506.2
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.d.ts +20 -0
- package/dist/build.js +64 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +81 -0
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.js +245 -0
- package/dist/config/_sampleFeature.d.ts +10 -0
- package/dist/config/_sampleFeature.js +11 -0
- package/dist/config/assetRules.d.ts +11 -0
- package/dist/config/assetRules.js +50 -0
- package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
- package/dist/config/bundleAnalyzerPlugin.js +19 -0
- package/dist/config/compressPlugin.d.ts +10 -0
- package/dist/config/compressPlugin.js +83 -0
- package/dist/config/config.d.ts +27 -0
- package/dist/config/config.js +218 -0
- package/dist/config/copyPlugin.d.ts +10 -0
- package/dist/config/copyPlugin.js +38 -0
- package/dist/config/cssRules.d.ts +11 -0
- package/dist/config/cssRules.js +108 -0
- package/dist/config/definePlugin.d.ts +15 -0
- package/dist/config/definePlugin.js +37 -0
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +120 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +70 -0
- package/dist/config/fastRefreshPlugin.d.ts +12 -0
- package/dist/config/fastRefreshPlugin.js +23 -0
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +23 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +31 -0
- package/dist/config/ignorePlugin.d.ts +10 -0
- package/dist/config/ignorePlugin.js +16 -0
- package/dist/config/javaScriptRules.d.ts +16 -0
- package/dist/config/javaScriptRules.js +177 -0
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +17 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
- package/dist/config/miniCSSExtractPlugin.js +22 -0
- package/dist/config/nodePolyfill.d.ts +10 -0
- package/dist/config/nodePolyfill.js +28 -0
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +14 -0
- package/dist/config/progressPlugin.d.ts +11 -0
- package/dist/config/progressPlugin.js +16 -0
- package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
- package/dist/config/purgecssWebpackPlugin.js +21 -0
- package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
- package/dist/config/speedMeasureWebpackPlugin.js +23 -0
- package/dist/config/svgRules.d.ts +12 -0
- package/dist/config/svgRules.js +53 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +24 -0
- package/dist/dev.d.ts +25 -0
- package/dist/dev.js +134 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +20 -0
- package/dist/loader/svgr.d.ts +4 -0
- package/dist/loader/svgr.js +58 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +74 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +11 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +52 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +73 -0
- package/dist/plugins/ProgressPlugin.d.ts +15 -0
- package/dist/plugins/ProgressPlugin.js +44 -0
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
- package/dist/plugins/_SamplePlugin.d.ts +9 -0
- package/dist/plugins/_SamplePlugin.js +14 -0
- package/dist/requireHook.d.ts +1 -0
- package/dist/requireHook.js +31 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +84 -0
- package/dist/server/server.d.ts +17 -0
- package/dist/server/server.js +193 -0
- package/dist/server/ws.d.ts +11 -0
- package/dist/server/ws.js +42 -0
- package/dist/swcPlugins/autoCSSModules.d.ts +13 -0
- package/dist/swcPlugins/autoCSSModules.js +34 -0
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +10 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
- package/dist/swcPlugins/lockCoreJS.js +24 -0
- package/dist/types.d.ts +119 -0
- package/dist/types.js +30 -0
- package/dist/utils/browsersList.d.ts +5 -0
- package/dist/utils/browsersList.js +10 -0
- package/dist/utils/depMatch.d.ts +6 -0
- package/dist/utils/depMatch.js +46 -0
- package/dist/utils/formatWebpackMessages.d.ts +12 -0
- package/dist/utils/formatWebpackMessages.js +100 -0
- package/dist/utils/getEsBuildTarget.d.ts +5 -0
- package/dist/utils/getEsBuildTarget.js +12 -0
- package/package.json +5 -5
package/dist/schema.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSchemas = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const options = [
|
|
6
|
+
'cheap-source-map',
|
|
7
|
+
'cheap-eval-source-map',
|
|
8
|
+
'cheap-hidden-source-map',
|
|
9
|
+
'cheap-inline-source-map',
|
|
10
|
+
'cheap-module-source-map',
|
|
11
|
+
'cheap-module-eval-source-map',
|
|
12
|
+
'cheap-module-hidden-source-map',
|
|
13
|
+
'cheap-module-inline-source-map',
|
|
14
|
+
'eval',
|
|
15
|
+
'eval-source-map',
|
|
16
|
+
'source-map',
|
|
17
|
+
'hidden-source-map',
|
|
18
|
+
'inline-source-map',
|
|
19
|
+
];
|
|
20
|
+
const DEVTOOL_REGEX = new RegExp('^' + // start of string
|
|
21
|
+
'(#@|@|#)?' + // maybe one of the pragmas
|
|
22
|
+
`(${options.join('$|')})`);
|
|
23
|
+
function getSchemas() {
|
|
24
|
+
return {
|
|
25
|
+
alias: (Joi) => Joi.object(),
|
|
26
|
+
autoCSSModules: (Joi) => Joi.boolean(),
|
|
27
|
+
autoprefixer: (Joi) => Joi.object(),
|
|
28
|
+
chainWebpack: (Joi) => Joi.function(),
|
|
29
|
+
copy: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.object({
|
|
30
|
+
from: Joi.string(),
|
|
31
|
+
to: Joi.string(),
|
|
32
|
+
}), Joi.string())),
|
|
33
|
+
cssLoader: (Joi) => Joi.object(),
|
|
34
|
+
cssLoaderModules: (Joi) => Joi.object(),
|
|
35
|
+
cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.parcelCSS, types_1.CSSMinifier.none),
|
|
36
|
+
cssMinifierOptions: (Joi) => Joi.object(),
|
|
37
|
+
deadCode: (Joi) => Joi.object(),
|
|
38
|
+
define: (Joi) => Joi.object(),
|
|
39
|
+
depTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
40
|
+
devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
|
|
41
|
+
esm: (Joi) => Joi.object(),
|
|
42
|
+
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
43
|
+
extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
|
|
44
|
+
extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
45
|
+
extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
46
|
+
extraPostCSSPlugins: (Joi) => Joi.array(),
|
|
47
|
+
fastRefresh: (Joi) => Joi.boolean(),
|
|
48
|
+
forkTSChecker: (Joi) => Joi.object(),
|
|
49
|
+
hash: (Joi) => Joi.boolean(),
|
|
50
|
+
https: (Joi) => Joi.object(),
|
|
51
|
+
ignoreMomentLocale: (Joi) => Joi.boolean(),
|
|
52
|
+
inlineLimit: (Joi) => Joi.number(),
|
|
53
|
+
jsMinifier: (Joi) => Joi.string().valid(types_1.JSMinifier.esbuild, types_1.JSMinifier.swc, types_1.JSMinifier.terser, types_1.JSMinifier.uglifyJs, types_1.JSMinifier.none),
|
|
54
|
+
jsMinifierOptions: (Joi) => Joi.object(),
|
|
55
|
+
lessLoader: (Joi) => Joi.object(),
|
|
56
|
+
manifest: (Joi) => Joi.object(),
|
|
57
|
+
mdx: (Joi) => Joi.object({
|
|
58
|
+
loader: Joi.string(),
|
|
59
|
+
loaderOptions: Joi.object(),
|
|
60
|
+
}),
|
|
61
|
+
mfsu: (Joi) => Joi.alternatives(Joi.object({
|
|
62
|
+
cacheDirectory: Joi.string(),
|
|
63
|
+
chainWebpack: Joi.function(),
|
|
64
|
+
esbuild: Joi.boolean(),
|
|
65
|
+
mfName: Joi.string(),
|
|
66
|
+
runtimePublicPath: Joi.boolean(),
|
|
67
|
+
}), Joi.boolean()),
|
|
68
|
+
outputPath: (Joi) => Joi.string(),
|
|
69
|
+
postcssLoader: (Joi) => Joi.object(),
|
|
70
|
+
proxy: (Joi) => Joi.object(),
|
|
71
|
+
publicPath: (Joi) => Joi.string(),
|
|
72
|
+
purgeCSS: (Joi) => Joi.object(),
|
|
73
|
+
runtimePublicPath: (Joi) => Joi.object(),
|
|
74
|
+
sassLoader: (Joi) => Joi.object(),
|
|
75
|
+
srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
76
|
+
styleLoader: (Joi) => Joi.object(),
|
|
77
|
+
svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
|
|
78
|
+
svgr: (Joi) => Joi.object(),
|
|
79
|
+
targets: (Joi) => Joi.object(),
|
|
80
|
+
theme: (Joi) => Joi.object(),
|
|
81
|
+
writeToDisk: (Joi) => Joi.boolean(),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.getSchemas = getSchemas;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import { IConfig } from '../types';
|
|
5
|
+
interface IOpts {
|
|
6
|
+
cwd: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
host?: string;
|
|
9
|
+
webpackConfig: Configuration;
|
|
10
|
+
userConfig: IConfig;
|
|
11
|
+
beforeMiddlewares?: any[];
|
|
12
|
+
afterMiddlewares?: any[];
|
|
13
|
+
onDevCompileDone?: Function;
|
|
14
|
+
onProgress?: Function;
|
|
15
|
+
}
|
|
16
|
+
export declare function createServer(opts: IOpts): Promise<http.Server | import("https").Server | null>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createServer = void 0;
|
|
7
|
+
const bundler_utils_1 = require("@umijs/bundler-utils");
|
|
8
|
+
const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
|
|
9
|
+
const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
|
|
10
|
+
const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
|
|
11
|
+
const utils_1 = require("@umijs/utils");
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const http_1 = __importDefault(require("http"));
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
const ws_1 = require("./ws");
|
|
17
|
+
async function createServer(opts) {
|
|
18
|
+
const { webpackConfig, userConfig } = opts;
|
|
19
|
+
const { proxy } = userConfig;
|
|
20
|
+
const app = (0, express_1.default)();
|
|
21
|
+
// cros
|
|
22
|
+
app.use((_req, res, next) => {
|
|
23
|
+
res.header('Access-Control-Allow-Origin', '*');
|
|
24
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
|
|
25
|
+
res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
|
|
26
|
+
next();
|
|
27
|
+
});
|
|
28
|
+
// compression
|
|
29
|
+
app.use(require('@umijs/bundler-webpack/compiled/compression')());
|
|
30
|
+
// TODO: headers
|
|
31
|
+
// before middlewares
|
|
32
|
+
(opts.beforeMiddlewares || []).forEach((m) => app.use(m));
|
|
33
|
+
// TODO: add to before middleware
|
|
34
|
+
app.use((req, res, next) => {
|
|
35
|
+
if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
|
|
36
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
37
|
+
(0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
next();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// webpack dev middleware
|
|
44
|
+
const configs = Array.isArray(webpackConfig)
|
|
45
|
+
? webpackConfig
|
|
46
|
+
: [webpackConfig];
|
|
47
|
+
const progresses = [];
|
|
48
|
+
if (opts.onProgress) {
|
|
49
|
+
configs.forEach((config) => {
|
|
50
|
+
const progress = {
|
|
51
|
+
percent: 0,
|
|
52
|
+
status: 'waiting',
|
|
53
|
+
};
|
|
54
|
+
progresses.push(progress);
|
|
55
|
+
config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
|
|
56
|
+
progress.percent = percent;
|
|
57
|
+
progress.status = msg;
|
|
58
|
+
opts.onProgress({ progresses });
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const compiler = (0, webpack_1.default)(configs);
|
|
63
|
+
const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
|
|
64
|
+
const compilerMiddleware = webpackDevMiddleware(compiler, {
|
|
65
|
+
publicPath: userConfig.publicPath || '/',
|
|
66
|
+
writeToDisk: userConfig.writeToDisk,
|
|
67
|
+
stats: 'none',
|
|
68
|
+
// watchOptions: { ignored }
|
|
69
|
+
});
|
|
70
|
+
app.use(compilerMiddleware);
|
|
71
|
+
// hmr hooks
|
|
72
|
+
let stats;
|
|
73
|
+
let isFirstCompile = true;
|
|
74
|
+
compiler.compilers.forEach(addHooks);
|
|
75
|
+
function addHooks(compiler) {
|
|
76
|
+
compiler.hooks.invalid.tap('server', () => {
|
|
77
|
+
sendMessage(constants_1.MESSAGE_TYPE.invalid);
|
|
78
|
+
});
|
|
79
|
+
compiler.hooks.done.tap('server', (_stats) => {
|
|
80
|
+
var _a;
|
|
81
|
+
stats = _stats;
|
|
82
|
+
sendStats(getStats(stats));
|
|
83
|
+
(_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
|
|
84
|
+
stats,
|
|
85
|
+
isFirstCompile,
|
|
86
|
+
time: stats.endTime - stats.startTime,
|
|
87
|
+
});
|
|
88
|
+
isFirstCompile = false;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function sendStats(stats, force, sender) {
|
|
92
|
+
const shouldEmit = !force &&
|
|
93
|
+
stats &&
|
|
94
|
+
(!stats.errors || stats.errors.length === 0) &&
|
|
95
|
+
(!stats.warnings || stats.warnings.length === 0) &&
|
|
96
|
+
stats.assets &&
|
|
97
|
+
stats.assets.every((asset) => !asset.emitted);
|
|
98
|
+
if (shouldEmit) {
|
|
99
|
+
sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
sendMessage(constants_1.MESSAGE_TYPE.hash, stats.hash, sender);
|
|
103
|
+
if ((stats.errors && stats.errors.length > 0) ||
|
|
104
|
+
(stats.warnings && stats.warnings.length > 0)) {
|
|
105
|
+
if (stats.warnings && stats.warnings.length > 0) {
|
|
106
|
+
sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
|
|
107
|
+
}
|
|
108
|
+
if (stats.errors && stats.errors.length > 0) {
|
|
109
|
+
sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function getStats(stats) {
|
|
117
|
+
return stats.toJson({
|
|
118
|
+
all: false,
|
|
119
|
+
hash: true,
|
|
120
|
+
assets: true,
|
|
121
|
+
warnings: true,
|
|
122
|
+
errors: true,
|
|
123
|
+
errorDetails: false,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function sendMessage(type, data, sender) {
|
|
127
|
+
(sender || ws).send(JSON.stringify({ type, data }));
|
|
128
|
+
}
|
|
129
|
+
// mock
|
|
130
|
+
// proxy
|
|
131
|
+
if (proxy) {
|
|
132
|
+
Object.keys(proxy).forEach((key) => {
|
|
133
|
+
const proxyConfig = proxy[key];
|
|
134
|
+
const target = proxyConfig.target;
|
|
135
|
+
if (target) {
|
|
136
|
+
app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, {
|
|
137
|
+
...proxy[key],
|
|
138
|
+
// Add x-real-url in response header
|
|
139
|
+
onProxyRes(proxyRes, req) {
|
|
140
|
+
var _a;
|
|
141
|
+
proxyRes.headers['x-real-url'] =
|
|
142
|
+
((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
|
|
143
|
+
},
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// after middlewares
|
|
149
|
+
(opts.afterMiddlewares || []).forEach((m) => {
|
|
150
|
+
// TODO: FIXME
|
|
151
|
+
app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
|
|
152
|
+
});
|
|
153
|
+
// history fallback
|
|
154
|
+
app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
|
|
155
|
+
index: '/',
|
|
156
|
+
}));
|
|
157
|
+
// hmr reconnect ping
|
|
158
|
+
app.use('/__umi_ping', (_, res) => {
|
|
159
|
+
res.end('pong');
|
|
160
|
+
});
|
|
161
|
+
// index.html
|
|
162
|
+
// TODO: remove me
|
|
163
|
+
app.get('/', (_req, res, next) => {
|
|
164
|
+
res.set('Content-Type', 'text/html');
|
|
165
|
+
const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
|
|
166
|
+
if ((0, fs_1.existsSync)(htmlPath)) {
|
|
167
|
+
(0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
next();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const server = userConfig.https
|
|
174
|
+
? await (0, bundler_utils_1.createHttpsServer)(app, userConfig.https)
|
|
175
|
+
: http_1.default.createServer(app);
|
|
176
|
+
if (!server) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const ws = (0, ws_1.createWebSocketServer)(server);
|
|
180
|
+
ws.wss.on('connection', (socket) => {
|
|
181
|
+
if (stats) {
|
|
182
|
+
sendStats(getStats(stats), false, socket);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const protocol = userConfig.https ? 'https:' : 'http:';
|
|
186
|
+
const port = opts.port || 8000;
|
|
187
|
+
server.listen(port, () => {
|
|
188
|
+
const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
|
|
189
|
+
utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
|
|
190
|
+
});
|
|
191
|
+
return server;
|
|
192
|
+
}
|
|
193
|
+
exports.createServer = createServer;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SpdyServer as Server } from '@umijs/bundler-utils';
|
|
3
|
+
import { Server as HttpServer } from 'http';
|
|
4
|
+
import { Http2Server } from 'http2';
|
|
5
|
+
import { Server as HttpsServer } from 'https';
|
|
6
|
+
import WebSocket from '../../compiled/ws';
|
|
7
|
+
export declare function createWebSocketServer(server: HttpServer | HttpsServer | Http2Server | Server): {
|
|
8
|
+
send(message: string): void;
|
|
9
|
+
wss: WebSocket.Server;
|
|
10
|
+
close(): void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createWebSocketServer = void 0;
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const ws_1 = __importDefault(require("../../compiled/ws"));
|
|
9
|
+
function createWebSocketServer(server) {
|
|
10
|
+
const wss = new ws_1.default.Server({
|
|
11
|
+
noServer: true,
|
|
12
|
+
});
|
|
13
|
+
server.on('upgrade', (req, socket, head) => {
|
|
14
|
+
if (req.headers['sec-websocket-protocol'] === 'webpack-hmr') {
|
|
15
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
16
|
+
wss.emit('connection', ws, req);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
wss.on('connection', (socket) => {
|
|
21
|
+
socket.send(JSON.stringify({ type: 'connected' }));
|
|
22
|
+
});
|
|
23
|
+
wss.on('error', (e) => {
|
|
24
|
+
if (e.code !== 'EADDRINUSE') {
|
|
25
|
+
console.error(utils_1.chalk.red(`WebSocket server error:\n${e.stack || e.message}`));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
send(message) {
|
|
30
|
+
wss.clients.forEach((client) => {
|
|
31
|
+
if (client.readyState === ws_1.default.OPEN) {
|
|
32
|
+
client.send(message);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
wss,
|
|
37
|
+
close() {
|
|
38
|
+
wss.close();
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.createWebSocketServer = createWebSocketServer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ImportDeclaration, ModuleItem, TsType } from '@swc/core';
|
|
2
|
+
import Visitor from '@swc/core/Visitor';
|
|
3
|
+
declare class AutoCSSModule extends Visitor {
|
|
4
|
+
visitTsType(expression: TsType): TsType;
|
|
5
|
+
/**
|
|
6
|
+
* call path:
|
|
7
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
8
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
9
|
+
*/
|
|
10
|
+
visitModuleItem(n: ModuleItem): ImportDeclaration | import("@swc/core").ExportDeclaration | import("@swc/core").ExportNamedDeclaration | import("@swc/core").ExportDefaultDeclaration | import("@swc/core").ExportDefaultExpression | import("@swc/core").ExportAllDeclaration | import("@swc/core").TsImportEqualsDeclaration | import("@swc/core").TsExportAssignment | import("@swc/core").TsNamespaceExportDeclaration | import("@swc/core").ExpressionStatement | import("@swc/core").BlockStatement | import("@swc/core").EmptyStatement | import("@swc/core").DebuggerStatement | import("@swc/core").WithStatement | import("@swc/core").ReturnStatement | import("@swc/core").LabeledStatement | import("@swc/core").BreakStatement | import("@swc/core").ContinueStatement | import("@swc/core").IfStatement | import("@swc/core").SwitchStatement | import("@swc/core").ThrowStatement | import("@swc/core").TryStatement | import("@swc/core").WhileStatement | import("@swc/core").DoWhileStatement | import("@swc/core").ForStatement | import("@swc/core").ForInStatement | import("@swc/core").ForOfStatement | import("@swc/core").ClassDeclaration | import("@swc/core").FunctionDeclaration | import("@swc/core").VariableDeclaration | import("@swc/core").TsInterfaceDeclaration | import("@swc/core").TsTypeAliasDeclaration | import("@swc/core").TsEnumDeclaration | import("@swc/core").TsModuleDeclaration;
|
|
11
|
+
visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
|
|
12
|
+
}
|
|
13
|
+
export default AutoCSSModule;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const changeImportFromString_1 = require("./changeImportFromString");
|
|
9
|
+
class AutoCSSModule extends Visitor_1.default {
|
|
10
|
+
visitTsType(expression) {
|
|
11
|
+
return expression;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* call path:
|
|
15
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
16
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
17
|
+
*/
|
|
18
|
+
visitModuleItem(n) {
|
|
19
|
+
if (n.type === 'ImportDeclaration') {
|
|
20
|
+
return this.visitImportDeclaration(n);
|
|
21
|
+
}
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
visitImportDeclaration(expression) {
|
|
25
|
+
const { specifiers, source } = expression;
|
|
26
|
+
const { value } = source;
|
|
27
|
+
if (specifiers.length && (0, utils_1.isStyleFile)({ filename: value })) {
|
|
28
|
+
const newImportFrom = `${value}?modules`;
|
|
29
|
+
(0, changeImportFromString_1.changeImportFromString)(expression, newImportFrom);
|
|
30
|
+
}
|
|
31
|
+
return expression;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = AutoCSSModule;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changeImportFromString = void 0;
|
|
4
|
+
const changeImportFromString = (e, v) => {
|
|
5
|
+
e.source.value = v;
|
|
6
|
+
// sync change to `raw`
|
|
7
|
+
// https://github.com/swc-project/swc/issues/4128
|
|
8
|
+
e.source.raw = `'${v}'`;
|
|
9
|
+
};
|
|
10
|
+
exports.changeImportFromString = changeImportFromString;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const changeImportFromString_1 = require("./changeImportFromString");
|
|
10
|
+
function addLastSlash(path) {
|
|
11
|
+
return path.endsWith('/') ? path : `${path}/`;
|
|
12
|
+
}
|
|
13
|
+
class LockCoreJS extends Visitor_1.default {
|
|
14
|
+
visitImportDeclaration(expression) {
|
|
15
|
+
const { source } = expression;
|
|
16
|
+
let { value, type } = source;
|
|
17
|
+
if (type === 'StringLiteral' && value.startsWith('core-js/')) {
|
|
18
|
+
const newValue = value.replace(/^core-js\//, addLastSlash((0, utils_1.winPath)((0, path_1.dirname)(require.resolve('core-js/package.json')))));
|
|
19
|
+
(0, changeImportFromString_1.changeImportFromString)(expression, newValue);
|
|
20
|
+
}
|
|
21
|
+
return expression;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = LockCoreJS;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { Config as SwcConfig } from '@swc/core';
|
|
2
|
+
import type { HttpsServerOptions } from '@umijs/bundler-utils';
|
|
3
|
+
import type { Options as ProxyOptions } from '../compiled/http-proxy-middleware';
|
|
4
|
+
import { Configuration } from '../compiled/webpack';
|
|
5
|
+
import Config from '../compiled/webpack-5-chain';
|
|
6
|
+
export declare enum Env {
|
|
7
|
+
development = "development",
|
|
8
|
+
production = "production"
|
|
9
|
+
}
|
|
10
|
+
export declare enum Transpiler {
|
|
11
|
+
babel = "babel",
|
|
12
|
+
swc = "swc",
|
|
13
|
+
esbuild = "esbuild",
|
|
14
|
+
none = "none"
|
|
15
|
+
}
|
|
16
|
+
export declare enum JSMinifier {
|
|
17
|
+
terser = "terser",
|
|
18
|
+
swc = "swc",
|
|
19
|
+
esbuild = "esbuild",
|
|
20
|
+
uglifyJs = "uglifyJs",
|
|
21
|
+
none = "none"
|
|
22
|
+
}
|
|
23
|
+
export declare enum CSSMinifier {
|
|
24
|
+
esbuild = "esbuild",
|
|
25
|
+
cssnano = "cssnano",
|
|
26
|
+
parcelCSS = "parcelCSS",
|
|
27
|
+
none = "none"
|
|
28
|
+
}
|
|
29
|
+
export interface ICopy {
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
}
|
|
33
|
+
declare type WebpackConfig = Required<Configuration>;
|
|
34
|
+
declare type IBabelPlugin = Function | string | [string, {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}];
|
|
37
|
+
export interface DeadCodeParams {
|
|
38
|
+
patterns?: string[];
|
|
39
|
+
exclude?: string[];
|
|
40
|
+
failOnHint?: boolean;
|
|
41
|
+
detectUnusedFiles?: boolean;
|
|
42
|
+
detectUnusedExport?: boolean;
|
|
43
|
+
context?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface IConfig {
|
|
46
|
+
alias?: Record<string, string>;
|
|
47
|
+
autoCSSModules?: boolean;
|
|
48
|
+
base?: string;
|
|
49
|
+
chainWebpack?: Function;
|
|
50
|
+
copy?: ICopy[] | string[];
|
|
51
|
+
cssLoader?: {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
};
|
|
54
|
+
cssLoaderModules?: {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
};
|
|
57
|
+
cssMinifier?: CSSMinifier;
|
|
58
|
+
cssMinifierOptions?: {
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
};
|
|
61
|
+
define?: {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
};
|
|
64
|
+
depTranspiler?: Transpiler;
|
|
65
|
+
devtool?: Config.DevTool;
|
|
66
|
+
deadCode?: DeadCodeParams;
|
|
67
|
+
https?: HttpsServerOptions;
|
|
68
|
+
externals?: WebpackConfig['externals'];
|
|
69
|
+
esm?: {
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
};
|
|
72
|
+
extraBabelPlugins?: IBabelPlugin[];
|
|
73
|
+
extraBabelPresets?: IBabelPlugin[];
|
|
74
|
+
extraBabelIncludes?: string[];
|
|
75
|
+
extraPostCSSPlugins?: any[];
|
|
76
|
+
hash?: boolean;
|
|
77
|
+
ignoreMomentLocale?: boolean;
|
|
78
|
+
jsMinifier?: JSMinifier;
|
|
79
|
+
jsMinifierOptions?: {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
};
|
|
82
|
+
lessLoader?: {
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
};
|
|
85
|
+
outputPath?: string;
|
|
86
|
+
postcssLoader?: {
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
};
|
|
89
|
+
proxy?: {
|
|
90
|
+
[key: string]: ProxyOptions;
|
|
91
|
+
};
|
|
92
|
+
publicPath?: string;
|
|
93
|
+
purgeCSS?: {
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
};
|
|
96
|
+
sassLoader?: {
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
};
|
|
99
|
+
srcTranspiler?: Transpiler;
|
|
100
|
+
styleLoader?: {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
};
|
|
103
|
+
svgr?: {
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
};
|
|
106
|
+
svgo?: {
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
} | false;
|
|
109
|
+
targets?: {
|
|
110
|
+
[key: string]: any;
|
|
111
|
+
};
|
|
112
|
+
writeToDisk?: boolean;
|
|
113
|
+
[key: string]: any;
|
|
114
|
+
}
|
|
115
|
+
export interface SwcOptions extends SwcConfig {
|
|
116
|
+
sync?: boolean;
|
|
117
|
+
parseMap?: boolean;
|
|
118
|
+
}
|
|
119
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CSSMinifier = exports.JSMinifier = exports.Transpiler = exports.Env = void 0;
|
|
4
|
+
var Env;
|
|
5
|
+
(function (Env) {
|
|
6
|
+
Env["development"] = "development";
|
|
7
|
+
Env["production"] = "production";
|
|
8
|
+
})(Env = exports.Env || (exports.Env = {}));
|
|
9
|
+
var Transpiler;
|
|
10
|
+
(function (Transpiler) {
|
|
11
|
+
Transpiler["babel"] = "babel";
|
|
12
|
+
Transpiler["swc"] = "swc";
|
|
13
|
+
Transpiler["esbuild"] = "esbuild";
|
|
14
|
+
Transpiler["none"] = "none";
|
|
15
|
+
})(Transpiler = exports.Transpiler || (exports.Transpiler = {}));
|
|
16
|
+
var JSMinifier;
|
|
17
|
+
(function (JSMinifier) {
|
|
18
|
+
JSMinifier["terser"] = "terser";
|
|
19
|
+
JSMinifier["swc"] = "swc";
|
|
20
|
+
JSMinifier["esbuild"] = "esbuild";
|
|
21
|
+
JSMinifier["uglifyJs"] = "uglifyJs";
|
|
22
|
+
JSMinifier["none"] = "none";
|
|
23
|
+
})(JSMinifier = exports.JSMinifier || (exports.JSMinifier = {}));
|
|
24
|
+
var CSSMinifier;
|
|
25
|
+
(function (CSSMinifier) {
|
|
26
|
+
CSSMinifier["esbuild"] = "esbuild";
|
|
27
|
+
CSSMinifier["cssnano"] = "cssnano";
|
|
28
|
+
CSSMinifier["parcelCSS"] = "parcelCSS";
|
|
29
|
+
CSSMinifier["none"] = "none";
|
|
30
|
+
})(CSSMinifier = exports.CSSMinifier || (exports.CSSMinifier = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrowsersList = void 0;
|
|
4
|
+
function getBrowsersList({ targets }) {
|
|
5
|
+
return (targets.browsers ||
|
|
6
|
+
Object.keys(targets).map((key) => {
|
|
7
|
+
return `${key} >= ${targets[key] === true ? '0' : targets[key]}`;
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
exports.getBrowsersList = getBrowsersList;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.es5ImcompatibleVersionsToPkg = exports.isMatch = exports.cleanCache = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const cache = new Map();
|
|
7
|
+
function cleanCache() {
|
|
8
|
+
cache.clear();
|
|
9
|
+
}
|
|
10
|
+
exports.cleanCache = cleanCache;
|
|
11
|
+
function isMatch(opts) {
|
|
12
|
+
// cache by dir, 命中率会更高
|
|
13
|
+
const dir = (0, utils_1.winPath)((0, path_1.dirname)(opts.path));
|
|
14
|
+
if (cache.has(dir)) {
|
|
15
|
+
return !!cache.get(dir);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const pkgPath = utils_1.pkgUp.pkgUpSync({ cwd: opts.path });
|
|
19
|
+
let ret;
|
|
20
|
+
if (!pkgPath) {
|
|
21
|
+
ret = false;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { name, version } = require(pkgPath);
|
|
25
|
+
if (opts.pkgs[name]) {
|
|
26
|
+
ret = opts.pkgs[name].some((v) => {
|
|
27
|
+
return utils_1.semver.satisfies(version, v);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
ret = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
cache.set(dir, ret);
|
|
35
|
+
return ret;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.isMatch = isMatch;
|
|
39
|
+
function es5ImcompatibleVersionsToPkg() {
|
|
40
|
+
const { config: { 'es5-imcompatible-versions': config }, } = require('es5-imcompatible-versions/package.json');
|
|
41
|
+
return Object.keys(config).reduce((memo, key) => {
|
|
42
|
+
memo[key] = /* versions */ Object.keys(config[key]);
|
|
43
|
+
return memo;
|
|
44
|
+
}, {});
|
|
45
|
+
}
|
|
46
|
+
exports.es5ImcompatibleVersionsToPkg = es5ImcompatibleVersionsToPkg;
|