@umijs/bundler-webpack 4.2.6-alpha.6 → 4.2.6-alpha.9
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 +22 -0
- package/dist/build.js +151 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +96 -0
- package/dist/config/_sampleFeature.d.ts +10 -0
- package/dist/config/_sampleFeature.js +35 -0
- package/dist/config/assetRules.d.ts +11 -0
- package/dist/config/assetRules.js +48 -0
- package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
- package/dist/config/bundleAnalyzerPlugin.js +43 -0
- package/dist/config/compressPlugin.d.ts +10 -0
- package/dist/config/compressPlugin.js +128 -0
- package/dist/config/config.d.ts +31 -0
- package/dist/config/config.js +243 -0
- package/dist/config/copyPlugin.d.ts +10 -0
- package/dist/config/copyPlugin.js +63 -0
- package/dist/config/cssRules.d.ts +11 -0
- package/dist/config/cssRules.js +165 -0
- package/dist/config/definePlugin.d.ts +16 -0
- package/dist/config/definePlugin.js +80 -0
- package/dist/config/detectCssModulesInDependence.d.ts +10 -0
- package/dist/config/detectCssModulesInDependence.js +151 -0
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +191 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +82 -0
- package/dist/config/fastRefreshPlugin.d.ts +12 -0
- package/dist/config/fastRefreshPlugin.js +49 -0
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +49 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +53 -0
- package/dist/config/ignorePlugin.d.ts +10 -0
- package/dist/config/ignorePlugin.js +40 -0
- package/dist/config/javaScriptRules.d.ts +16 -0
- package/dist/config/javaScriptRules.js +191 -0
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +40 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
- package/dist/config/miniCSSExtractPlugin.js +55 -0
- package/dist/config/nodePolyfill.d.ts +10 -0
- package/dist/config/nodePolyfill.js +51 -0
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +38 -0
- package/dist/config/progressPlugin.d.ts +11 -0
- package/dist/config/progressPlugin.js +53 -0
- package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
- package/dist/config/purgecssWebpackPlugin.js +43 -0
- package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
- package/dist/config/speedMeasureWebpackPlugin.js +59 -0
- package/dist/config/ssrPlugin.d.ts +11 -0
- package/dist/config/ssrPlugin.js +98 -0
- package/dist/config/svgRules.d.ts +12 -0
- package/dist/config/svgRules.js +70 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +59 -0
- package/dist/dev.d.ts +40 -0
- package/dist/dev.js +208 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +32 -0
- package/dist/loader/svgr.d.ts +4 -0
- package/dist/loader/svgr.js +84 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +149 -0
- package/dist/parcelCSS.d.ts +2 -0
- package/dist/parcelCSS.js +39 -0
- package/dist/plugins/EsbuildMinifyFix.d.ts +8 -0
- package/dist/plugins/EsbuildMinifyFix.js +136 -0
- package/dist/plugins/ProgressPlugin.d.ts +15 -0
- package/dist/plugins/ProgressPlugin.js +69 -0
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +45 -0
- package/dist/plugins/_SamplePlugin.d.ts +9 -0
- package/dist/plugins/_SamplePlugin.js +37 -0
- package/dist/requireHook.d.ts +1 -0
- package/dist/requireHook.js +49 -0
- package/dist/schema.d.ts +4 -0
- package/dist/schema.js +178 -0
- package/dist/server/server.d.ts +17 -0
- package/dist/server/server.js +223 -0
- package/dist/server/ws.d.ts +13 -0
- package/dist/server/ws.js +76 -0
- package/dist/swcPlugins/autoCSSModules.d.ts +17 -0
- package/dist/swcPlugins/autoCSSModules.js +63 -0
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +32 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
- package/dist/swcPlugins/lockCoreJS.js +56 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.js +61 -0
- package/dist/utils/browsersList.d.ts +5 -0
- package/dist/utils/browsersList.js +33 -0
- package/dist/utils/depMatch.d.ts +6 -0
- package/dist/utils/depMatch.js +72 -0
- package/dist/utils/formatWebpackMessages.d.ts +12 -0
- package/dist/utils/formatWebpackMessages.js +128 -0
- package/dist/utils/getEsBuildTarget.d.ts +7 -0
- package/dist/utils/getEsBuildTarget.js +46 -0
- package/dist/utils/pkgUpContainsName.d.ts +1 -0
- package/dist/utils/pkgUpContainsName.js +50 -0
- package/package.json +5 -5
package/dist/schema.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/schema.ts
|
|
20
|
+
var schema_exports = {};
|
|
21
|
+
__export(schema_exports, {
|
|
22
|
+
getSchemas: () => getSchemas
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(schema_exports);
|
|
25
|
+
var import_types = require("./types");
|
|
26
|
+
var devTool = [
|
|
27
|
+
"cheap-source-map",
|
|
28
|
+
"cheap-module-source-map",
|
|
29
|
+
"eval",
|
|
30
|
+
"eval-source-map",
|
|
31
|
+
"eval-cheap-source-map",
|
|
32
|
+
"eval-cheap-module-source-map",
|
|
33
|
+
"eval-nosources-cheap-source-map",
|
|
34
|
+
"eval-nosources-cheap-module-source-map",
|
|
35
|
+
"eval-nosources-source-map",
|
|
36
|
+
"source-map",
|
|
37
|
+
"hidden-source-map",
|
|
38
|
+
"hidden-nosources-cheap-source-map",
|
|
39
|
+
"hidden-nosources-cheap-module-source-map",
|
|
40
|
+
"hidden-nosources-source-map",
|
|
41
|
+
"hidden-cheap-source-map",
|
|
42
|
+
"hidden-cheap-module-source-map",
|
|
43
|
+
"inline-source-map",
|
|
44
|
+
"inline-cheap-source-map",
|
|
45
|
+
"inline-cheap-module-source-map",
|
|
46
|
+
"inline-nosources-cheap-source-map",
|
|
47
|
+
"inline-nosources-cheap-module-source-map",
|
|
48
|
+
"inline-nosources-source-map",
|
|
49
|
+
"nosources-source-map",
|
|
50
|
+
"nosources-cheap-source-map",
|
|
51
|
+
"nosources-cheap-module-source-map"
|
|
52
|
+
];
|
|
53
|
+
function getSchemas() {
|
|
54
|
+
return {
|
|
55
|
+
alias: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
56
|
+
autoCSSModules: ({ zod }) => zod.boolean(),
|
|
57
|
+
autoprefixer: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
58
|
+
babelLoaderCustomize: ({ zod }) => zod.string(),
|
|
59
|
+
cacheDirectoryPath: ({ zod }) => zod.string(),
|
|
60
|
+
chainWebpack: ({ zod }) => zod.function(),
|
|
61
|
+
checkDepCssModules: ({ zod }) => zod.boolean().default(false),
|
|
62
|
+
copy: ({ zod }) => zod.array(
|
|
63
|
+
zod.union([
|
|
64
|
+
zod.object({
|
|
65
|
+
from: zod.string(),
|
|
66
|
+
to: zod.string()
|
|
67
|
+
}),
|
|
68
|
+
zod.string()
|
|
69
|
+
])
|
|
70
|
+
),
|
|
71
|
+
cssLoader: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
72
|
+
cssLoaderModules: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
73
|
+
cssMinifier: ({ zod }) => zod.enum([
|
|
74
|
+
import_types.CSSMinifier.cssnano,
|
|
75
|
+
import_types.CSSMinifier.esbuild,
|
|
76
|
+
import_types.CSSMinifier.parcelCSS,
|
|
77
|
+
import_types.CSSMinifier.none
|
|
78
|
+
]),
|
|
79
|
+
cssMinifierOptions: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
80
|
+
cssPublicPath: ({ zod }) => zod.string(),
|
|
81
|
+
deadCode: ({ zod }) => zod.object({
|
|
82
|
+
context: zod.string(),
|
|
83
|
+
detectUnusedExport: zod.boolean(),
|
|
84
|
+
detectUnusedFiles: zod.boolean(),
|
|
85
|
+
exclude: zod.array(zod.string()),
|
|
86
|
+
failOnHint: zod.boolean(),
|
|
87
|
+
patterns: zod.array(zod.string())
|
|
88
|
+
}).deepPartial(),
|
|
89
|
+
define: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
90
|
+
depTranspiler: ({ zod }) => zod.enum([
|
|
91
|
+
import_types.Transpiler.babel,
|
|
92
|
+
import_types.Transpiler.esbuild,
|
|
93
|
+
import_types.Transpiler.swc,
|
|
94
|
+
import_types.Transpiler.none
|
|
95
|
+
]),
|
|
96
|
+
devtool: ({ zod }) => zod.union([zod.enum(devTool), zod.boolean()]),
|
|
97
|
+
esm: ({ zod }) => zod.object({}),
|
|
98
|
+
externals: ({ zod }) => zod.union([
|
|
99
|
+
zod.record(zod.string(), zod.any()),
|
|
100
|
+
zod.string(),
|
|
101
|
+
zod.function()
|
|
102
|
+
]),
|
|
103
|
+
extraBabelIncludes: ({ zod }) => zod.array(zod.union([zod.string(), zod.instanceof(RegExp)])),
|
|
104
|
+
extraBabelPlugins: ({ zod }) => zod.array(zod.union([zod.string(), zod.array(zod.any())])),
|
|
105
|
+
extraBabelPresets: ({ zod }) => zod.array(zod.union([zod.string(), zod.array(zod.any())])),
|
|
106
|
+
extraPostCSSPlugins: ({ zod }) => zod.array(zod.any()),
|
|
107
|
+
fastRefresh: ({ zod }) => zod.boolean(),
|
|
108
|
+
forkTSChecker: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
109
|
+
hash: ({ zod }) => zod.boolean(),
|
|
110
|
+
https: ({ zod }) => zod.object({
|
|
111
|
+
cert: zod.string(),
|
|
112
|
+
hosts: zod.array(zod.string()),
|
|
113
|
+
http2: zod.boolean(),
|
|
114
|
+
key: zod.string()
|
|
115
|
+
}).deepPartial(),
|
|
116
|
+
ignoreMomentLocale: ({ zod }) => zod.boolean(),
|
|
117
|
+
inlineLimit: ({ zod }) => zod.number(),
|
|
118
|
+
jsMinifier: ({ zod }) => zod.enum([
|
|
119
|
+
import_types.JSMinifier.esbuild,
|
|
120
|
+
import_types.JSMinifier.swc,
|
|
121
|
+
import_types.JSMinifier.terser,
|
|
122
|
+
import_types.JSMinifier.uglifyJs,
|
|
123
|
+
import_types.JSMinifier.none
|
|
124
|
+
]),
|
|
125
|
+
jsMinifierOptions: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
126
|
+
lessLoader: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
127
|
+
manifest: ({ zod }) => zod.object({
|
|
128
|
+
basePath: zod.string(),
|
|
129
|
+
fileName: zod.string()
|
|
130
|
+
}).deepPartial(),
|
|
131
|
+
mdx: ({ zod }) => zod.object({
|
|
132
|
+
loader: zod.string(),
|
|
133
|
+
loaderOptions: zod.record(zod.string(), zod.any())
|
|
134
|
+
}).deepPartial(),
|
|
135
|
+
mfsu: ({ zod }) => zod.union([
|
|
136
|
+
zod.object({
|
|
137
|
+
cacheDirectory: zod.string(),
|
|
138
|
+
chainWebpack: zod.function(),
|
|
139
|
+
esbuild: zod.boolean(),
|
|
140
|
+
exclude: zod.array(
|
|
141
|
+
zod.union([zod.string(), zod.instanceof(RegExp)])
|
|
142
|
+
),
|
|
143
|
+
include: zod.array(zod.string()),
|
|
144
|
+
mfName: zod.string(),
|
|
145
|
+
remoteAliases: zod.array(zod.string()),
|
|
146
|
+
remoteName: zod.string(),
|
|
147
|
+
runtimePublicPath: zod.boolean(),
|
|
148
|
+
shared: zod.record(zod.string(), zod.any()),
|
|
149
|
+
strategy: zod.enum(["eager", "normal"]).default("normal")
|
|
150
|
+
}).deepPartial(),
|
|
151
|
+
zod.boolean()
|
|
152
|
+
]),
|
|
153
|
+
normalCSSLoaderModules: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
154
|
+
outputPath: ({ zod }) => zod.string(),
|
|
155
|
+
postcssLoader: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
156
|
+
proxy: ({ zod }) => zod.union([zod.record(zod.string(), zod.any()), zod.array(zod.any())]),
|
|
157
|
+
publicPath: ({ zod }) => zod.string(),
|
|
158
|
+
purgeCSS: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
159
|
+
runtimePublicPath: ({ zod }) => zod.object({}),
|
|
160
|
+
sassLoader: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
161
|
+
srcTranspiler: ({ zod }) => zod.enum([import_types.Transpiler.babel, import_types.Transpiler.esbuild, import_types.Transpiler.swc]),
|
|
162
|
+
srcTranspilerOptions: ({ zod }) => zod.object({
|
|
163
|
+
esbuild: zod.record(zod.string(), zod.any()),
|
|
164
|
+
swc: zod.record(zod.string(), zod.any())
|
|
165
|
+
}).deepPartial(),
|
|
166
|
+
styleLoader: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
167
|
+
stylusLoader: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
168
|
+
svgo: ({ zod }) => zod.union([zod.record(zod.string(), zod.any()), zod.boolean()]),
|
|
169
|
+
svgr: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
170
|
+
targets: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
171
|
+
theme: ({ zod }) => zod.record(zod.string(), zod.any()),
|
|
172
|
+
writeToDisk: ({ zod }) => zod.boolean()
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
176
|
+
0 && (module.exports = {
|
|
177
|
+
getSchemas
|
|
178
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
|
|
2
|
+
import { IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
cwd: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
host?: string;
|
|
7
|
+
ip?: string;
|
|
8
|
+
webpackConfig: Configuration;
|
|
9
|
+
userConfig: IConfig;
|
|
10
|
+
beforeMiddlewares?: any[];
|
|
11
|
+
afterMiddlewares?: any[];
|
|
12
|
+
onDevCompileDone?: Function;
|
|
13
|
+
onProgress?: Function;
|
|
14
|
+
onBeforeMiddleware?: Function;
|
|
15
|
+
}
|
|
16
|
+
export declare function createServer(opts: IOpts): Promise<any>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/server/server.ts
|
|
30
|
+
var server_exports = {};
|
|
31
|
+
__export(server_exports, {
|
|
32
|
+
createServer: () => createServer
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(server_exports);
|
|
35
|
+
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
36
|
+
var import_express = __toESM(require("@umijs/bundler-utils/compiled/express"));
|
|
37
|
+
var import_webpack = __toESM(require("@umijs/bundler-webpack/compiled/webpack"));
|
|
38
|
+
var import_utils = require("@umijs/utils");
|
|
39
|
+
var import_cors = __toESM(require("cors"));
|
|
40
|
+
var import_fs = require("fs");
|
|
41
|
+
var import_http = __toESM(require("http"));
|
|
42
|
+
var import_path = require("path");
|
|
43
|
+
var import_constants = require("../constants");
|
|
44
|
+
var import_ws = require("./ws");
|
|
45
|
+
async function createServer(opts) {
|
|
46
|
+
const { webpackConfig, userConfig } = opts;
|
|
47
|
+
const { proxy } = userConfig;
|
|
48
|
+
const app = (0, import_express.default)();
|
|
49
|
+
let ws;
|
|
50
|
+
app.use(
|
|
51
|
+
(0, import_cors.default)({
|
|
52
|
+
origin: true,
|
|
53
|
+
methods: ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
|
|
54
|
+
credentials: true
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
if (process.env.UMI_DEV_SERVER_COMPRESS !== "none") {
|
|
58
|
+
app.use(require("@umijs/bundler-webpack/compiled/compression")());
|
|
59
|
+
}
|
|
60
|
+
app.use((req, res, next) => {
|
|
61
|
+
const file = req.path;
|
|
62
|
+
const filePath = (0, import_path.join)(opts.cwd, file);
|
|
63
|
+
const ext = (0, import_path.extname)(filePath);
|
|
64
|
+
if (ext === ".js" && (0, import_fs.existsSync)(filePath)) {
|
|
65
|
+
import_utils.logger.info(
|
|
66
|
+
"[dev]",
|
|
67
|
+
`${file} is responded with ${filePath}, remove it to use original file`
|
|
68
|
+
);
|
|
69
|
+
res.sendFile(filePath);
|
|
70
|
+
} else {
|
|
71
|
+
next();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (opts.onBeforeMiddleware) {
|
|
75
|
+
opts.onBeforeMiddleware(app);
|
|
76
|
+
}
|
|
77
|
+
(opts.beforeMiddlewares || []).forEach((m) => app.use(m));
|
|
78
|
+
const configs = Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig];
|
|
79
|
+
const progresses = [];
|
|
80
|
+
if (opts.onProgress) {
|
|
81
|
+
configs.forEach((config) => {
|
|
82
|
+
const progress = {
|
|
83
|
+
percent: 0,
|
|
84
|
+
status: "waiting",
|
|
85
|
+
details: []
|
|
86
|
+
};
|
|
87
|
+
progresses.push(progress);
|
|
88
|
+
config.plugins.push(
|
|
89
|
+
new import_webpack.default.ProgressPlugin((percent, msg, ...details) => {
|
|
90
|
+
progress.percent = percent;
|
|
91
|
+
progress.status = msg;
|
|
92
|
+
progress.details = details;
|
|
93
|
+
opts.onProgress({ progresses });
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const compiler = (0, import_webpack.default)(configs);
|
|
99
|
+
const webpackDevMiddleware = require("@umijs/bundler-webpack/compiled/webpack-dev-middleware");
|
|
100
|
+
const compilerMiddleware = webpackDevMiddleware(compiler, {
|
|
101
|
+
publicPath: userConfig.publicPath || "/",
|
|
102
|
+
writeToDisk: userConfig.writeToDisk,
|
|
103
|
+
stats: "none"
|
|
104
|
+
// watchOptions: { ignored }
|
|
105
|
+
});
|
|
106
|
+
app.use(compilerMiddleware);
|
|
107
|
+
let stats;
|
|
108
|
+
let isFirstCompile = true;
|
|
109
|
+
compiler.compilers.forEach(addHooks);
|
|
110
|
+
function addHooks(compiler2) {
|
|
111
|
+
compiler2.hooks.invalid.tap("server", () => {
|
|
112
|
+
sendMessage(import_constants.MESSAGE_TYPE.invalid);
|
|
113
|
+
});
|
|
114
|
+
compiler2.hooks.done.tap("server", (_stats) => {
|
|
115
|
+
var _a;
|
|
116
|
+
stats = _stats;
|
|
117
|
+
sendStats(getStats(stats));
|
|
118
|
+
(_a = opts.onDevCompileDone) == null ? void 0 : _a.call(opts, {
|
|
119
|
+
stats,
|
|
120
|
+
isFirstCompile,
|
|
121
|
+
ws,
|
|
122
|
+
time: stats.endTime - stats.startTime
|
|
123
|
+
});
|
|
124
|
+
isFirstCompile = false;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function sendStats(stats2, force, sender) {
|
|
128
|
+
const shouldEmit = !force && stats2 && (!stats2.errors || stats2.errors.length === 0) && (!stats2.warnings || stats2.warnings.length === 0) && stats2.assets && stats2.assets.every((asset) => !asset.emitted);
|
|
129
|
+
if (shouldEmit) {
|
|
130
|
+
sendMessage(import_constants.MESSAGE_TYPE.stillOk, null, sender);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
sendMessage(import_constants.MESSAGE_TYPE.hash, stats2.hash, sender);
|
|
134
|
+
if (stats2.errors && stats2.errors.length > 0 || stats2.warnings && stats2.warnings.length > 0) {
|
|
135
|
+
if (stats2.warnings && stats2.warnings.length > 0) {
|
|
136
|
+
sendMessage(import_constants.MESSAGE_TYPE.warnings, stats2.warnings, sender);
|
|
137
|
+
}
|
|
138
|
+
if (stats2.errors && stats2.errors.length > 0) {
|
|
139
|
+
sendMessage(import_constants.MESSAGE_TYPE.errors, stats2.errors, sender);
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
sendMessage(import_constants.MESSAGE_TYPE.ok, null, sender);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function getStats(stats2) {
|
|
146
|
+
return stats2.toJson({
|
|
147
|
+
all: false,
|
|
148
|
+
hash: true,
|
|
149
|
+
assets: true,
|
|
150
|
+
warnings: true,
|
|
151
|
+
errors: true,
|
|
152
|
+
errorDetails: false
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function sendMessage(type, data, sender) {
|
|
156
|
+
var _a;
|
|
157
|
+
(_a = sender || ws) == null ? void 0 : _a.send(JSON.stringify({ type, data }));
|
|
158
|
+
}
|
|
159
|
+
if (proxy) {
|
|
160
|
+
(0, import_bundler_utils.createProxy)(proxy, app);
|
|
161
|
+
}
|
|
162
|
+
(opts.afterMiddlewares || []).forEach((m) => {
|
|
163
|
+
app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
|
|
164
|
+
});
|
|
165
|
+
app.use(
|
|
166
|
+
require("@umijs/bundler-webpack/compiled/connect-history-api-fallback")({
|
|
167
|
+
index: "/"
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
app.use("/__umi_ping", (_, res) => {
|
|
171
|
+
res.end("pong");
|
|
172
|
+
});
|
|
173
|
+
app.get("/", (_req, res, next) => {
|
|
174
|
+
res.set("Content-Type", "text/html");
|
|
175
|
+
const htmlPath = (0, import_path.join)(opts.cwd, "index.html");
|
|
176
|
+
if ((0, import_fs.existsSync)(htmlPath)) {
|
|
177
|
+
(0, import_fs.createReadStream)(htmlPath).on("error", next).pipe(res);
|
|
178
|
+
} else {
|
|
179
|
+
next();
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
let server;
|
|
183
|
+
if (userConfig.https) {
|
|
184
|
+
const httpsOpts = userConfig.https;
|
|
185
|
+
if (!httpsOpts.hosts) {
|
|
186
|
+
httpsOpts.hosts = import_utils.lodash.uniq(
|
|
187
|
+
[
|
|
188
|
+
...httpsOpts.hosts || [],
|
|
189
|
+
// always add localhost, 127.0.0.1, ip and host
|
|
190
|
+
"127.0.0.1",
|
|
191
|
+
"localhost",
|
|
192
|
+
opts.ip,
|
|
193
|
+
opts.host !== "0.0.0.0" && opts.host
|
|
194
|
+
].filter(Boolean)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
server = await (0, import_bundler_utils.createHttpsServer)(app, httpsOpts);
|
|
198
|
+
} else {
|
|
199
|
+
server = import_http.default.createServer(app);
|
|
200
|
+
}
|
|
201
|
+
if (!server) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
ws = (0, import_ws.createWebSocketServer)(server);
|
|
205
|
+
ws.wss.on("connection", (socket) => {
|
|
206
|
+
if (stats) {
|
|
207
|
+
sendStats(getStats(stats), false, socket);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
const protocol = userConfig.https ? "https:" : "http:";
|
|
211
|
+
const port = opts.port || 8e3;
|
|
212
|
+
server.listen(port, () => {
|
|
213
|
+
const banner = (0, import_utils.getDevBanner)(protocol, opts.host, port);
|
|
214
|
+
console.log(banner.before);
|
|
215
|
+
import_utils.logger.ready(banner.main);
|
|
216
|
+
console.log(banner.after);
|
|
217
|
+
});
|
|
218
|
+
return server;
|
|
219
|
+
}
|
|
220
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
+
0 && (module.exports = {
|
|
222
|
+
createServer
|
|
223
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { SpdyServer as Server } from '@umijs/bundler-utils';
|
|
5
|
+
import { Server as HttpServer } from 'http';
|
|
6
|
+
import { Http2Server } from 'http2';
|
|
7
|
+
import { Server as HttpsServer } from 'https';
|
|
8
|
+
import WebSocket from '../../compiled/ws';
|
|
9
|
+
export declare function createWebSocketServer(server: HttpServer | HttpsServer | Http2Server | Server): {
|
|
10
|
+
send(message: string): void;
|
|
11
|
+
wss: WebSocket.Server<WebSocket.WebSocket>;
|
|
12
|
+
close(): void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/server/ws.ts
|
|
30
|
+
var ws_exports = {};
|
|
31
|
+
__export(ws_exports, {
|
|
32
|
+
createWebSocketServer: () => createWebSocketServer
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(ws_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_ws = __toESM(require("../../compiled/ws"));
|
|
37
|
+
function createWebSocketServer(server) {
|
|
38
|
+
const wss = new import_ws.default.Server({
|
|
39
|
+
noServer: true
|
|
40
|
+
});
|
|
41
|
+
server.on("upgrade", (req, socket, head) => {
|
|
42
|
+
if (req.headers["sec-websocket-protocol"] === "webpack-hmr") {
|
|
43
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
44
|
+
wss.emit("connection", ws, req);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
wss.on("connection", (socket) => {
|
|
49
|
+
socket.send(JSON.stringify({ type: "connected" }));
|
|
50
|
+
});
|
|
51
|
+
wss.on("error", (e) => {
|
|
52
|
+
if (e.code !== "EADDRINUSE") {
|
|
53
|
+
console.error(
|
|
54
|
+
import_utils.chalk.red(`WebSocket server error:
|
|
55
|
+
${e.stack || e.message}`)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
send(message) {
|
|
61
|
+
wss.clients.forEach((client) => {
|
|
62
|
+
if (client.readyState === import_ws.default.OPEN) {
|
|
63
|
+
client.send(message);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
wss,
|
|
68
|
+
close() {
|
|
69
|
+
wss.close();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
createWebSocketServer
|
|
76
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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").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 | import("@swc/core").ExpressionStatement;
|
|
11
|
+
visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Swc will not support js plugin in the future.
|
|
15
|
+
* See https://github.com/swc-project/website/commit/fde42ad5371c1a16ca9729fe17bcfd3489841ac1
|
|
16
|
+
*/
|
|
17
|
+
export default AutoCSSModule;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/swcPlugins/autoCSSModules.ts
|
|
30
|
+
var autoCSSModules_exports = {};
|
|
31
|
+
__export(autoCSSModules_exports, {
|
|
32
|
+
default: () => autoCSSModules_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(autoCSSModules_exports);
|
|
35
|
+
var import_Visitor = __toESM(require("@swc/core/Visitor"));
|
|
36
|
+
var import_utils = require("@umijs/utils");
|
|
37
|
+
var import_changeImportFromString = require("./changeImportFromString");
|
|
38
|
+
var AutoCSSModule = class extends import_Visitor.default {
|
|
39
|
+
visitTsType(expression) {
|
|
40
|
+
return expression;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* call path:
|
|
44
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
45
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
46
|
+
*/
|
|
47
|
+
visitModuleItem(n) {
|
|
48
|
+
if (n.type === "ImportDeclaration") {
|
|
49
|
+
return this.visitImportDeclaration(n);
|
|
50
|
+
}
|
|
51
|
+
return n;
|
|
52
|
+
}
|
|
53
|
+
visitImportDeclaration(expression) {
|
|
54
|
+
const { specifiers, source } = expression;
|
|
55
|
+
const { value } = source;
|
|
56
|
+
if (specifiers.length && (0, import_utils.isStyleFile)({ filename: value })) {
|
|
57
|
+
const newImportFrom = `${value}?modules`;
|
|
58
|
+
(0, import_changeImportFromString.changeImportFromString)(expression, newImportFrom);
|
|
59
|
+
}
|
|
60
|
+
return expression;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var autoCSSModules_default = AutoCSSModule;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/swcPlugins/changeImportFromString.ts
|
|
20
|
+
var changeImportFromString_exports = {};
|
|
21
|
+
__export(changeImportFromString_exports, {
|
|
22
|
+
changeImportFromString: () => changeImportFromString
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(changeImportFromString_exports);
|
|
25
|
+
var changeImportFromString = (e, v) => {
|
|
26
|
+
e.source.value = v;
|
|
27
|
+
e.source.raw = `'${v}'`;
|
|
28
|
+
};
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
changeImportFromString
|
|
32
|
+
});
|