@umijs/bundler-webpack 4.0.0-canary.20220429.3 → 4.0.0-canary.20220429.4
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 +75 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +90 -0
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.js +258 -0
- package/dist/config/_sampleFeature.d.ts +10 -0
- package/dist/config/_sampleFeature.js +22 -0
- package/dist/config/assetRules.d.ts +11 -0
- package/dist/config/assetRules.js +61 -0
- package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
- package/dist/config/bundleAnalyzerPlugin.js +30 -0
- package/dist/config/compressPlugin.d.ts +10 -0
- package/dist/config/compressPlugin.js +91 -0
- package/dist/config/config.d.ts +27 -0
- package/dist/config/config.js +226 -0
- package/dist/config/copyPlugin.d.ts +10 -0
- package/dist/config/copyPlugin.js +49 -0
- package/dist/config/cssRules.d.ts +11 -0
- package/dist/config/cssRules.js +98 -0
- package/dist/config/definePlugin.d.ts +15 -0
- package/dist/config/definePlugin.js +45 -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 +75 -0
- package/dist/config/fastRefreshPlugin.d.ts +12 -0
- package/dist/config/fastRefreshPlugin.js +34 -0
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +34 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
- package/dist/config/ignorePlugin.d.ts +10 -0
- package/dist/config/ignorePlugin.js +27 -0
- package/dist/config/javaScriptRules.d.ts +16 -0
- package/dist/config/javaScriptRules.js +188 -0
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +25 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
- package/dist/config/miniCSSExtractPlugin.js +33 -0
- package/dist/config/nodePolyfill.d.ts +10 -0
- package/dist/config/nodePolyfill.js +35 -0
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +25 -0
- package/dist/config/progressPlugin.d.ts +11 -0
- package/dist/config/progressPlugin.js +27 -0
- package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
- package/dist/config/purgecssWebpackPlugin.js +32 -0
- package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
- package/dist/config/speedMeasureWebpackPlugin.js +34 -0
- package/dist/config/svgRules.d.ts +12 -0
- package/dist/config/svgRules.js +57 -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 +145 -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 +67 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +79 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +11 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +63 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +75 -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 +202 -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
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createServer = void 0;
|
|
16
|
+
const bundler_utils_1 = require("@umijs/bundler-utils");
|
|
17
|
+
const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
|
|
18
|
+
const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
|
|
19
|
+
const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
|
|
20
|
+
const utils_1 = require("@umijs/utils");
|
|
21
|
+
const fs_1 = require("fs");
|
|
22
|
+
const http_1 = __importDefault(require("http"));
|
|
23
|
+
const path_1 = require("path");
|
|
24
|
+
const constants_1 = require("../constants");
|
|
25
|
+
const ws_1 = require("./ws");
|
|
26
|
+
function createServer(opts) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const { webpackConfig, userConfig } = opts;
|
|
29
|
+
const { proxy } = userConfig;
|
|
30
|
+
const app = (0, express_1.default)();
|
|
31
|
+
// cros
|
|
32
|
+
app.use((_req, res, next) => {
|
|
33
|
+
res.header('Access-Control-Allow-Origin', '*');
|
|
34
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
|
|
35
|
+
res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
|
|
36
|
+
next();
|
|
37
|
+
});
|
|
38
|
+
// compression
|
|
39
|
+
app.use(require('@umijs/bundler-webpack/compiled/compression')());
|
|
40
|
+
// TODO: headers
|
|
41
|
+
// before middlewares
|
|
42
|
+
(opts.beforeMiddlewares || []).forEach((m) => app.use(m));
|
|
43
|
+
// TODO: add to before middleware
|
|
44
|
+
app.use((req, res, next) => {
|
|
45
|
+
if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
|
|
46
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
47
|
+
(0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
next();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
// webpack dev middleware
|
|
54
|
+
const configs = Array.isArray(webpackConfig)
|
|
55
|
+
? webpackConfig
|
|
56
|
+
: [webpackConfig];
|
|
57
|
+
const progresses = [];
|
|
58
|
+
if (opts.onProgress) {
|
|
59
|
+
configs.forEach((config) => {
|
|
60
|
+
const progress = {
|
|
61
|
+
percent: 0,
|
|
62
|
+
status: 'waiting',
|
|
63
|
+
};
|
|
64
|
+
progresses.push(progress);
|
|
65
|
+
config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
|
|
66
|
+
progress.percent = percent;
|
|
67
|
+
progress.status = msg;
|
|
68
|
+
opts.onProgress({ progresses });
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const compiler = (0, webpack_1.default)(configs);
|
|
73
|
+
const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
|
|
74
|
+
const compilerMiddleware = webpackDevMiddleware(compiler, {
|
|
75
|
+
publicPath: userConfig.publicPath || '/',
|
|
76
|
+
writeToDisk: userConfig.writeToDisk,
|
|
77
|
+
stats: 'none',
|
|
78
|
+
// watchOptions: { ignored }
|
|
79
|
+
});
|
|
80
|
+
app.use(compilerMiddleware);
|
|
81
|
+
// hmr hooks
|
|
82
|
+
let stats;
|
|
83
|
+
let isFirstCompile = true;
|
|
84
|
+
compiler.compilers.forEach(addHooks);
|
|
85
|
+
function addHooks(compiler) {
|
|
86
|
+
compiler.hooks.invalid.tap('server', () => {
|
|
87
|
+
sendMessage(constants_1.MESSAGE_TYPE.invalid);
|
|
88
|
+
});
|
|
89
|
+
compiler.hooks.done.tap('server', (_stats) => {
|
|
90
|
+
var _a;
|
|
91
|
+
stats = _stats;
|
|
92
|
+
sendStats(getStats(stats));
|
|
93
|
+
(_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
|
|
94
|
+
stats,
|
|
95
|
+
isFirstCompile,
|
|
96
|
+
time: stats.endTime - stats.startTime,
|
|
97
|
+
});
|
|
98
|
+
isFirstCompile = false;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function sendStats(stats, force, sender) {
|
|
102
|
+
const shouldEmit = !force &&
|
|
103
|
+
stats &&
|
|
104
|
+
(!stats.errors || stats.errors.length === 0) &&
|
|
105
|
+
(!stats.warnings || stats.warnings.length === 0) &&
|
|
106
|
+
stats.assets &&
|
|
107
|
+
stats.assets.every((asset) => !asset.emitted);
|
|
108
|
+
if (shouldEmit) {
|
|
109
|
+
sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
sendMessage(constants_1.MESSAGE_TYPE.hash, stats.hash, sender);
|
|
113
|
+
if ((stats.errors && stats.errors.length > 0) ||
|
|
114
|
+
(stats.warnings && stats.warnings.length > 0)) {
|
|
115
|
+
if (stats.warnings && stats.warnings.length > 0) {
|
|
116
|
+
sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
|
|
117
|
+
}
|
|
118
|
+
if (stats.errors && stats.errors.length > 0) {
|
|
119
|
+
sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function getStats(stats) {
|
|
127
|
+
return stats.toJson({
|
|
128
|
+
all: false,
|
|
129
|
+
hash: true,
|
|
130
|
+
assets: true,
|
|
131
|
+
warnings: true,
|
|
132
|
+
errors: true,
|
|
133
|
+
errorDetails: false,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function sendMessage(type, data, sender) {
|
|
137
|
+
(sender || ws).send(JSON.stringify({ type, data }));
|
|
138
|
+
}
|
|
139
|
+
// mock
|
|
140
|
+
// proxy
|
|
141
|
+
if (proxy) {
|
|
142
|
+
Object.keys(proxy).forEach((key) => {
|
|
143
|
+
const proxyConfig = proxy[key];
|
|
144
|
+
const target = proxyConfig.target;
|
|
145
|
+
if (target) {
|
|
146
|
+
app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, Object.assign(Object.assign({}, proxy[key]), {
|
|
147
|
+
// Add x-real-url in response header
|
|
148
|
+
onProxyRes(proxyRes, req) {
|
|
149
|
+
var _a;
|
|
150
|
+
proxyRes.headers['x-real-url'] =
|
|
151
|
+
((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
|
|
152
|
+
} })));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
// after middlewares
|
|
157
|
+
(opts.afterMiddlewares || []).forEach((m) => {
|
|
158
|
+
// TODO: FIXME
|
|
159
|
+
app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
|
|
160
|
+
});
|
|
161
|
+
// history fallback
|
|
162
|
+
app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
|
|
163
|
+
index: '/',
|
|
164
|
+
}));
|
|
165
|
+
// hmr reconnect ping
|
|
166
|
+
app.use('/__umi_ping', (_, res) => {
|
|
167
|
+
res.end('pong');
|
|
168
|
+
});
|
|
169
|
+
// index.html
|
|
170
|
+
// TODO: remove me
|
|
171
|
+
app.get('/', (_req, res, next) => {
|
|
172
|
+
res.set('Content-Type', 'text/html');
|
|
173
|
+
const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
|
|
174
|
+
if ((0, fs_1.existsSync)(htmlPath)) {
|
|
175
|
+
(0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
next();
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
const server = userConfig.https
|
|
182
|
+
? yield (0, bundler_utils_1.createHttpsServer)(app, userConfig.https)
|
|
183
|
+
: http_1.default.createServer(app);
|
|
184
|
+
if (!server) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const ws = (0, ws_1.createWebSocketServer)(server);
|
|
188
|
+
ws.wss.on('connection', (socket) => {
|
|
189
|
+
if (stats) {
|
|
190
|
+
sendStats(getStats(stats), false, socket);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
const protocol = userConfig.https ? 'https:' : 'http:';
|
|
194
|
+
const port = opts.port || 8000;
|
|
195
|
+
server.listen(port, () => {
|
|
196
|
+
const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
|
|
197
|
+
utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
|
|
198
|
+
});
|
|
199
|
+
return server;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function formatMessage(message: string | {
|
|
2
|
+
message: string;
|
|
3
|
+
} | {
|
|
4
|
+
message: string;
|
|
5
|
+
}[]): string;
|
|
6
|
+
export declare function formatWebpackMessages(json: {
|
|
7
|
+
errors: string[];
|
|
8
|
+
warnings: string[];
|
|
9
|
+
}): {
|
|
10
|
+
errors: string[];
|
|
11
|
+
warnings: string[];
|
|
12
|
+
};
|