@umijs/bundler-webpack 4.0.0-beta.9 → 4.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/autoprefixer/browserslist/index.d.ts +11 -7
- package/compiled/autoprefixer/index.js +3 -3
- package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
- package/compiled/autoprefixer/postcss/lib/declaration.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
- package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
- package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
- package/compiled/autoprefixer/postcss/lib/node.d.ts +36 -2
- package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
- package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
- package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
- package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
- package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
- package/compiled/babel-loader/index.js +2 -2
- package/compiled/copy-webpack-plugin/576.index.js +1171 -0
- package/compiled/copy-webpack-plugin/index.js +16 -10
- package/compiled/copy-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
- package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
- package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
- package/compiled/cssnano/index.js +12 -11
- package/compiled/express/index.js +57 -74
- package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
- package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
- package/compiled/fork-ts-checker-webpack-plugin/index.js +48 -0
- package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
- package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
- package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
- package/compiled/http-proxy-middleware/index.js +10 -10
- package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
- package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
- package/compiled/mini-css-extract-plugin/index.js +8103 -7617
- package/compiled/mini-css-extract-plugin/loader.js +177 -54
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +83 -24
- package/compiled/postcss-loader/index.js +1 -1
- package/compiled/react-refresh/index.js +3 -3
- package/compiled/sass-loader/index.js +1 -1
- package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
- package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
- package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
- package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
- package/compiled/schema-utils/declarations/validate.d.ts +4 -4
- package/compiled/schema-utils/index.js +8 -2
- package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/style-loader/index.js +1 -1
- package/compiled/terser/index.js +1 -1
- package/compiled/terser-webpack-plugin/index.js +393 -517
- package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
- package/compiled/terser-webpack-plugin/minify.js +10 -3
- package/compiled/terser-webpack-plugin/package.json +1 -1
- package/compiled/terser-webpack-plugin/types/index.d.ts +183 -149
- package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
- package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -15
- package/compiled/terser-webpack-plugin/utils.js +118 -25
- package/compiled/webpack/index.js +10464 -5286
- package/compiled/webpack-dev-middleware/index.js +11 -5
- package/compiled/webpack-dev-middleware/package.json +1 -1
- package/compiled/webpack-manifest-plugin/LICENSE +21 -0
- package/compiled/webpack-manifest-plugin/index.js +1 -0
- package/compiled/webpack-manifest-plugin/package.json +1 -0
- package/compiled/webpack-sources/index.js +1 -1
- package/compiled/ws/index.d.ts +1 -2
- package/compiled/ws/index.js +1 -1
- package/dist/build.d.ts +5 -3
- package/dist/build.js +2 -1
- package/dist/cli.js +4 -7
- package/dist/config/assetRules.js +6 -14
- package/dist/config/compressPlugin.js +6 -0
- package/dist/config/config.d.ts +7 -2
- package/dist/config/config.js +49 -7
- package/dist/config/cssRules.js +1 -1
- 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 +71 -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/javaScriptRules.d.ts +1 -0
- package/dist/config/javaScriptRules.js +31 -20
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +25 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
- package/dist/config/miniCSSExtractPlugin.js +2 -3
- package/dist/config/svgRules.d.ts +1 -0
- package/dist/config/svgRules.js +17 -3
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/dev.d.ts +4 -2
- package/dist/dev.js +31 -5
- 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/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +74 -0
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
- package/dist/requireHook.js +1 -1
- package/dist/schema.js +14 -6
- package/dist/server/server.js +20 -1
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +13 -16
- package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
- package/dist/swcPlugins/lockCoreJS.js +23 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +1 -0
- package/dist/utils/depMatch.js +1 -1
- package/package.json +45 -39
- package/compiled/@svgr/webpack/LICENSE +0 -7
- package/compiled/@svgr/webpack/index.js +0 -266
- package/compiled/@svgr/webpack/package.json +0 -1
- package/compiled/swc-loader/LICENSE +0 -25
- package/compiled/swc-loader/index.js +0 -1
- package/compiled/swc-loader/package.json +0 -1
package/dist/config/svgRules.js
CHANGED
|
@@ -17,11 +17,25 @@ function addSVGRules(opts) {
|
|
|
17
17
|
if (svgr) {
|
|
18
18
|
const svgrRule = config.module.rule('svgr');
|
|
19
19
|
svgrRule
|
|
20
|
-
.test(/\.svg$/
|
|
20
|
+
.test(/\.svg$/)
|
|
21
21
|
.issuer(/\.[jt]sx?$/)
|
|
22
|
+
.type('javascript/auto')
|
|
22
23
|
.use('svgr-loader')
|
|
23
|
-
.loader(require.resolve('
|
|
24
|
-
.options(Object.assign(Object.assign({ svgoConfig: Object.assign({
|
|
24
|
+
.loader(require.resolve('../loader/svgr'))
|
|
25
|
+
.options(Object.assign(Object.assign({ svgoConfig: Object.assign({ plugins: [
|
|
26
|
+
{
|
|
27
|
+
name: 'preset-default',
|
|
28
|
+
params: {
|
|
29
|
+
overrides: {
|
|
30
|
+
removeTitle: false,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
] }, svgo) }, svgr), { svgo: !!svgo }))
|
|
35
|
+
.end()
|
|
36
|
+
.use('url-loader')
|
|
37
|
+
.loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
|
|
38
|
+
.end();
|
|
25
39
|
}
|
|
26
40
|
if (svgo === false) {
|
|
27
41
|
const svgRule = config.module.rule('svg');
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
|
|
3
|
+
exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
|
|
4
4
|
exports.DEFAULT_DEVTOOL = 'cheap-module-source-map';
|
|
5
5
|
exports.DEFAULT_OUTPUT_PATH = 'dist';
|
|
6
6
|
exports.MFSU_NAME = 'MFSU';
|
|
@@ -13,3 +13,6 @@ var MESSAGE_TYPE;
|
|
|
13
13
|
MESSAGE_TYPE["stillOk"] = "still-ok";
|
|
14
14
|
MESSAGE_TYPE["invalid"] = "invalid";
|
|
15
15
|
})(MESSAGE_TYPE = exports.MESSAGE_TYPE || (exports.MESSAGE_TYPE = {}));
|
|
16
|
+
exports.DEFAULT_BROWSER_TARGETS = {
|
|
17
|
+
chrome: 80,
|
|
18
|
+
};
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { IOpts as IConfigOpts } from './config/config';
|
|
1
2
|
import { IConfig } from './types';
|
|
2
|
-
|
|
3
|
+
declare type IOpts = {
|
|
3
4
|
afterMiddlewares?: any[];
|
|
4
5
|
beforeMiddlewares?: any[];
|
|
5
6
|
onDevCompileDone?: Function;
|
|
6
7
|
port?: number;
|
|
7
8
|
host?: string;
|
|
9
|
+
babelPreset?: any;
|
|
8
10
|
chainWebpack?: Function;
|
|
9
11
|
modifyWebpackConfig?: Function;
|
|
10
12
|
beforeBabelPlugins?: any[];
|
|
@@ -14,6 +16,6 @@ interface IOpts {
|
|
|
14
16
|
cwd: string;
|
|
15
17
|
config: IConfig;
|
|
16
18
|
entry: Record<string, string>;
|
|
17
|
-
}
|
|
19
|
+
} & Pick<IConfigOpts, 'cache'>;
|
|
18
20
|
export declare function dev(opts: IOpts): Promise<void>;
|
|
19
21
|
export {};
|
package/dist/dev.js
CHANGED
|
@@ -14,21 +14,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.dev = void 0;
|
|
16
16
|
const mfsu_1 = require("@umijs/mfsu");
|
|
17
|
+
const utils_1 = require("@umijs/utils");
|
|
18
|
+
const path_1 = require("path");
|
|
17
19
|
const webpack_1 = __importDefault(require("../compiled/webpack"));
|
|
18
20
|
const config_1 = require("./config/config");
|
|
19
21
|
const constants_1 = require("./constants");
|
|
20
22
|
const server_1 = require("./server/server");
|
|
21
23
|
const types_1 = require("./types");
|
|
22
24
|
function dev(opts) {
|
|
23
|
-
var _a;
|
|
24
|
-
var
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
var _f;
|
|
25
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
28
|
const enableMFSU = opts.config.mfsu !== false;
|
|
27
29
|
let mfsu = null;
|
|
28
30
|
if (enableMFSU) {
|
|
31
|
+
if (opts.config.srcTranspiler === types_1.Transpiler.swc) {
|
|
32
|
+
utils_1.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
|
|
33
|
+
}
|
|
29
34
|
mfsu = new mfsu_1.MFSU({
|
|
30
35
|
implementor: webpack_1.default,
|
|
31
36
|
buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
|
|
37
|
+
depBuildConfig: {
|
|
38
|
+
extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
|
|
39
|
+
},
|
|
40
|
+
mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
|
|
41
|
+
runtimePublicPath: opts.config.runtimePublicPath,
|
|
42
|
+
tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
|
|
43
|
+
(0, path_1.join)(opts.cwd, 'node_modules/.cache/mfsu'),
|
|
44
|
+
getCacheDependency() {
|
|
45
|
+
var _a;
|
|
46
|
+
return {
|
|
47
|
+
version: require('../package.json').version,
|
|
48
|
+
esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
|
|
49
|
+
};
|
|
50
|
+
},
|
|
32
51
|
});
|
|
33
52
|
}
|
|
34
53
|
const webpackConfig = yield (0, config_1.getConfig)({
|
|
@@ -36,6 +55,7 @@ function dev(opts) {
|
|
|
36
55
|
env: types_1.Env.development,
|
|
37
56
|
entry: opts.entry,
|
|
38
57
|
userConfig: opts.config,
|
|
58
|
+
babelPreset: opts.babelPreset,
|
|
39
59
|
extraBabelPlugins: [
|
|
40
60
|
...(opts.beforeBabelPlugins || []),
|
|
41
61
|
...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
|
|
@@ -45,10 +65,12 @@ function dev(opts) {
|
|
|
45
65
|
...(opts.beforeBabelPresets || []),
|
|
46
66
|
...(opts.extraBabelPresets || []),
|
|
47
67
|
],
|
|
68
|
+
extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
|
|
48
69
|
chainWebpack: opts.chainWebpack,
|
|
49
70
|
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
50
71
|
hmr: true,
|
|
51
72
|
analyze: process.env.ANALYZE,
|
|
73
|
+
cache: opts.cache,
|
|
52
74
|
});
|
|
53
75
|
const depConfig = yield (0, config_1.getConfig)({
|
|
54
76
|
cwd: opts.cwd,
|
|
@@ -58,17 +80,21 @@ function dev(opts) {
|
|
|
58
80
|
hash: true,
|
|
59
81
|
staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
|
|
60
82
|
name: constants_1.MFSU_NAME,
|
|
83
|
+
cache: {
|
|
84
|
+
buildDependencies: (_e = opts.cache) === null || _e === void 0 ? void 0 : _e.buildDependencies,
|
|
85
|
+
cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
|
|
86
|
+
},
|
|
61
87
|
});
|
|
62
|
-
(
|
|
88
|
+
(_f = webpackConfig.resolve).alias || (_f.alias = {});
|
|
63
89
|
// TODO: REMOVE ME
|
|
64
90
|
['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
|
|
65
91
|
// @ts-ignore
|
|
66
92
|
webpackConfig.resolve.alias[dep] = require.resolve(dep);
|
|
67
93
|
});
|
|
68
|
-
mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
|
|
94
|
+
yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
|
|
69
95
|
config: webpackConfig,
|
|
70
96
|
depConfig: depConfig,
|
|
71
|
-
});
|
|
97
|
+
}));
|
|
72
98
|
yield (0, server_1.createServer)({
|
|
73
99
|
webpackConfig,
|
|
74
100
|
userConfig: opts.config,
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
// MIT: https://github.com/gregberge/svgr/blob/main/packages/webpack/src/index.ts
|
|
16
|
+
// TODO: prebuild @svgr/core @svgr/plugin-jsx @svgr/plugin-svgo
|
|
17
|
+
const core_1 = require("@svgr/core");
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const plugin_jsx_1 = __importDefault(require("@svgr/plugin-jsx"));
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const plugin_svgo_1 = __importDefault(require("@svgr/plugin-svgo"));
|
|
22
|
+
const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
|
|
23
|
+
const path_1 = require("path");
|
|
24
|
+
const util_1 = require("util");
|
|
25
|
+
const tranformSvg = (0, util_1.callbackify)((contents, options, state) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const jsCode = yield (0, core_1.transform)(contents, options, state);
|
|
27
|
+
const result = yield (0, esbuild_1.transform)(jsCode, {
|
|
28
|
+
loader: 'tsx',
|
|
29
|
+
target: 'es2015',
|
|
30
|
+
});
|
|
31
|
+
if (!(result === null || result === void 0 ? void 0 : result.code)) {
|
|
32
|
+
throw new Error(`Error while transforming using Esbuild`);
|
|
33
|
+
}
|
|
34
|
+
return result.code;
|
|
35
|
+
}));
|
|
36
|
+
function svgrLoader(contents) {
|
|
37
|
+
this.cacheable && this.cacheable();
|
|
38
|
+
const callback = this.async();
|
|
39
|
+
const options = this.getOptions();
|
|
40
|
+
const previousExport = (() => {
|
|
41
|
+
if (contents.startsWith('export '))
|
|
42
|
+
return contents;
|
|
43
|
+
const exportMatches = contents.match(/^module.exports\s*=\s*(.*)/);
|
|
44
|
+
return exportMatches ? `export default ${exportMatches[1]}` : null;
|
|
45
|
+
})();
|
|
46
|
+
const state = {
|
|
47
|
+
caller: {
|
|
48
|
+
name: 'svgr-loader',
|
|
49
|
+
previousExport,
|
|
50
|
+
defaultPlugins: [plugin_svgo_1.default, plugin_jsx_1.default],
|
|
51
|
+
},
|
|
52
|
+
filePath: (0, path_1.normalize)(this.resourcePath),
|
|
53
|
+
};
|
|
54
|
+
if (!previousExport) {
|
|
55
|
+
tranformSvg(contents, options, state, callback);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.fs.readFile(this.resourcePath, (err, result) => {
|
|
59
|
+
if (err) {
|
|
60
|
+
callback(err);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
tranformSvg(String(result), options, state, callback);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = svgrLoader;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const core_1 = require("@swc/core");
|
|
15
|
+
const types_1 = require("../types");
|
|
16
|
+
function getBaseOpts({ filename }) {
|
|
17
|
+
const isTSFile = filename.endsWith('.ts');
|
|
18
|
+
const isTypeScript = isTSFile || filename.endsWith('.tsx');
|
|
19
|
+
const isDev = process.env.NODE_ENV === types_1.Env.development;
|
|
20
|
+
/**
|
|
21
|
+
* Not use swc auto polyfill , depend on `preset-umi/features/polyfill/polyfill` imported polyfill file
|
|
22
|
+
*
|
|
23
|
+
* @issue https://github.com/swc-project/swc/issues/2607
|
|
24
|
+
* https://github.com/swc-project/swc/issues/1604
|
|
25
|
+
*/
|
|
26
|
+
const swcOpts = {
|
|
27
|
+
module: {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
type: 'es6',
|
|
30
|
+
ignoreDynamic: true,
|
|
31
|
+
},
|
|
32
|
+
jsc: {
|
|
33
|
+
parser: {
|
|
34
|
+
syntax: isTypeScript ? 'typescript' : 'ecmascript',
|
|
35
|
+
[isTypeScript ? 'tsx' : 'jsx']: !isTSFile,
|
|
36
|
+
dynamicImport: isTypeScript,
|
|
37
|
+
},
|
|
38
|
+
target: 'es2015',
|
|
39
|
+
transform: {
|
|
40
|
+
react: {
|
|
41
|
+
runtime: 'automatic',
|
|
42
|
+
pragma: 'React.createElement',
|
|
43
|
+
pragmaFrag: 'React.Fragment',
|
|
44
|
+
throwIfNamespace: true,
|
|
45
|
+
development: isDev,
|
|
46
|
+
useBuiltins: true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
return swcOpts;
|
|
52
|
+
}
|
|
53
|
+
function swcLoader(contents) {
|
|
54
|
+
// 启用异步模式
|
|
55
|
+
const callback = this.async();
|
|
56
|
+
const loaderOpts = this.getOptions();
|
|
57
|
+
const { sync = false, parseMap = false } = loaderOpts, otherOpts = __rest(loaderOpts, ["sync", "parseMap"]);
|
|
58
|
+
const filename = this.resourcePath;
|
|
59
|
+
const swcOpts = Object.assign(Object.assign(Object.assign({}, getBaseOpts({
|
|
60
|
+
filename,
|
|
61
|
+
})), { filename, sourceMaps: this.sourceMap, sourceFileName: filename }), otherOpts);
|
|
62
|
+
try {
|
|
63
|
+
if (sync) {
|
|
64
|
+
const output = (0, core_1.transformSync)(contents, swcOpts);
|
|
65
|
+
callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
(0, core_1.transform)(contents, swcOpts).then((output) => {
|
|
69
|
+
callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
|
|
70
|
+
}, (err) => {
|
|
71
|
+
callback(err);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
callback(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.default = swcLoader;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TransformOptions } from '@parcel/css';
|
|
2
|
+
import type { Compiler } from '../../compiled/webpack/types';
|
|
3
|
+
declare type MinifyPluginOpts = Omit<TransformOptions, 'filename' | 'code' | 'minify'>;
|
|
4
|
+
export declare class ParcelCSSMinifyPlugin {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(opts?: MinifyPluginOpts);
|
|
7
|
+
apply(compiler: Compiler): void;
|
|
8
|
+
private transformAssets;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ParcelCSSMinifyPlugin = void 0;
|
|
13
|
+
const css_1 = require("@parcel/css");
|
|
14
|
+
const buffer_1 = require("buffer");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const webpack_sources_1 = require("../../compiled/webpack-sources");
|
|
17
|
+
const pkgPath = (0, path_1.join)(__dirname, '../../package.json');
|
|
18
|
+
const pkg = require(pkgPath);
|
|
19
|
+
const PLUGIN_NAME = 'parcel-css-minify-plugin';
|
|
20
|
+
const CSS_FILE_REG = /\.css(?:\?.*)?$/i;
|
|
21
|
+
class ParcelCSSMinifyPlugin {
|
|
22
|
+
constructor(opts = {}) {
|
|
23
|
+
this.options = opts;
|
|
24
|
+
}
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
const meta = JSON.stringify({
|
|
27
|
+
name: pkg.name,
|
|
28
|
+
version: pkg.version,
|
|
29
|
+
options: this.options,
|
|
30
|
+
});
|
|
31
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
32
|
+
compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
|
|
33
|
+
compilation.hooks.processAssets.tapPromise({
|
|
34
|
+
name: PLUGIN_NAME,
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
|
|
37
|
+
additionalAssets: true,
|
|
38
|
+
}, () => __awaiter(this, void 0, void 0, function* () { return yield this.transformAssets(compilation); }));
|
|
39
|
+
compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
|
|
40
|
+
statsPrinter.hooks.print
|
|
41
|
+
.for('asset.info.minimized')
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
.tap(PLUGIN_NAME, (minimized, { green, formatFlag }) => {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
return minimized ? green(formatFlag('minimized')) : undefined;
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
transformAssets(compilation) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const { options: { devtool }, } = compilation.compiler;
|
|
53
|
+
const sourcemap = this.options.sourceMap === undefined
|
|
54
|
+
? (devtool && devtool.includes('source-map'))
|
|
55
|
+
: this.options.sourceMap;
|
|
56
|
+
const assets = compilation.getAssets().filter((asset) => {
|
|
57
|
+
return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
|
|
58
|
+
});
|
|
59
|
+
yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const { source, map } = asset.source.sourceAndMap();
|
|
61
|
+
const sourceAsString = source.toString();
|
|
62
|
+
const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
|
|
63
|
+
const result = yield (0, css_1.transform)(Object.assign({ filename: asset.name, code, minify: true, sourceMap: sourcemap }, this.options));
|
|
64
|
+
const codeString = result.code.toString();
|
|
65
|
+
compilation.updateAsset(asset.name,
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
sourcemap
|
|
68
|
+
? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
|
|
69
|
+
: new webpack_sources_1.RawSource(codeString), Object.assign(Object.assign({}, asset.info), { minimized: true }));
|
|
70
|
+
})));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuntimePublicPathPlugin = void 0;
|
|
4
|
+
const PLUGIN_NAME = 'RuntimePublicPath';
|
|
5
|
+
// ref: https://gist.github.com/ScriptedAlchemy/60d0c49ce049184f6ce3e86ca351fdca
|
|
6
|
+
class RuntimePublicPathPlugin {
|
|
7
|
+
apply(compiler) {
|
|
8
|
+
compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
|
|
9
|
+
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module) => {
|
|
10
|
+
// The hook to get the public path ('__webpack_require__.p')
|
|
11
|
+
// https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
|
|
12
|
+
if (module.constructor.name === 'PublicPathRuntimeModule') {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
module._cachedGeneratedCode = `__webpack_require__.p = window.publicPath;`;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.RuntimePublicPathPlugin = RuntimePublicPathPlugin;
|
package/dist/requireHook.js
CHANGED
|
@@ -17,7 +17,7 @@ const hookPropertyMap = new Map([
|
|
|
17
17
|
['webpack/lib/webpack.js', '@umijs/bundler-webpack/compiled/webpack'],
|
|
18
18
|
]);
|
|
19
19
|
deepImports_json_1.default.forEach((item) => {
|
|
20
|
-
const name = item.split('/').
|
|
20
|
+
const name = item.split('/').pop();
|
|
21
21
|
hookPropertyMap.set(item, `@umijs/bundler-webpack/compiled/webpack/${name}`);
|
|
22
22
|
hookPropertyMap.set(`${item}.js`, `@umijs/bundler-webpack/compiled/webpack/${name}`);
|
|
23
23
|
});
|
package/dist/schema.js
CHANGED
|
@@ -24,6 +24,7 @@ function getSchemas() {
|
|
|
24
24
|
return {
|
|
25
25
|
alias: (Joi) => Joi.object(),
|
|
26
26
|
autoCSSModules: (Joi) => Joi.boolean(),
|
|
27
|
+
autoprefixer: (Joi) => Joi.object(),
|
|
27
28
|
chainWebpack: (Joi) => Joi.function(),
|
|
28
29
|
copy: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.object({
|
|
29
30
|
from: Joi.string(),
|
|
@@ -31,33 +32,40 @@ function getSchemas() {
|
|
|
31
32
|
}), Joi.string())),
|
|
32
33
|
cssLoader: (Joi) => Joi.object(),
|
|
33
34
|
cssLoaderModules: (Joi) => Joi.object(),
|
|
34
|
-
cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.none),
|
|
35
|
+
cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.parcelCSS, types_1.CSSMinifier.none),
|
|
35
36
|
cssMinifierOptions: (Joi) => Joi.object(),
|
|
36
37
|
define: (Joi) => Joi.object(),
|
|
38
|
+
deadCode: (Joi) => Joi.object(),
|
|
37
39
|
depTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
38
40
|
devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
|
|
39
|
-
externals: (Joi) => Joi.alternatives().try(Joi.object().
|
|
40
|
-
Joi.string(),
|
|
41
|
-
Joi.boolean(),
|
|
42
|
-
Joi.object().pattern(/.+/, [Joi.string(), Joi.boolean()]),
|
|
43
|
-
]), Joi.string(), Joi.func().arity(3), Joi.object().regex()),
|
|
41
|
+
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
44
42
|
extraBabelPlugins: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
|
|
45
43
|
extraBabelPresets: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
|
|
46
44
|
extraPostCSSPlugins: (Joi) => Joi.array(),
|
|
47
45
|
fastRefresh: (Joi) => Joi.boolean(),
|
|
46
|
+
forkTSChecker: (Joi) => Joi.object(),
|
|
48
47
|
hash: (Joi) => Joi.boolean(),
|
|
49
48
|
ignoreMomentLocale: (Joi) => Joi.boolean(),
|
|
49
|
+
inlineLimit: (Joi) => Joi.number(),
|
|
50
50
|
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),
|
|
51
51
|
jsMinifierOptions: (Joi) => Joi.object(),
|
|
52
52
|
lessLoader: (Joi) => Joi.object(),
|
|
53
|
+
manifest: (Joi) => Joi.object(),
|
|
54
|
+
mdx: (Joi) => Joi.object({
|
|
55
|
+
loader: Joi.string(),
|
|
56
|
+
loaderOptions: Joi.object(),
|
|
57
|
+
}),
|
|
53
58
|
mfsu: (Joi) => Joi.alternatives(Joi.object({
|
|
59
|
+
cacheDirectory: Joi.string(),
|
|
54
60
|
esbuild: Joi.boolean(),
|
|
61
|
+
mfName: Joi.string(),
|
|
55
62
|
}), Joi.boolean()),
|
|
56
63
|
outputPath: (Joi) => Joi.string(),
|
|
57
64
|
postcssLoader: (Joi) => Joi.object(),
|
|
58
65
|
proxy: (Joi) => Joi.object(),
|
|
59
66
|
publicPath: (Joi) => Joi.string(),
|
|
60
67
|
purgeCSS: (Joi) => Joi.object(),
|
|
68
|
+
runtimePublicPath: (Joi) => Joi.object(),
|
|
61
69
|
sassLoader: (Joi) => Joi.object(),
|
|
62
70
|
srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
63
71
|
styleLoader: (Joi) => Joi.object(),
|
package/dist/server/server.js
CHANGED
|
@@ -27,6 +27,25 @@ function createServer(opts) {
|
|
|
27
27
|
const { webpackConfig, userConfig } = opts;
|
|
28
28
|
const { proxy } = userConfig;
|
|
29
29
|
const app = (0, express_1.default)();
|
|
30
|
+
// basename middleware
|
|
31
|
+
app.use((req, _res, next) => {
|
|
32
|
+
const { url, path } = req;
|
|
33
|
+
const { basename, history } = userConfig;
|
|
34
|
+
if ((history === null || history === void 0 ? void 0 : history.type) === 'browser' &&
|
|
35
|
+
basename !== '/' &&
|
|
36
|
+
url.startsWith(basename)) {
|
|
37
|
+
req.url = url.slice(basename.length);
|
|
38
|
+
req.path = path.slice(basename.length);
|
|
39
|
+
}
|
|
40
|
+
next();
|
|
41
|
+
});
|
|
42
|
+
// cros
|
|
43
|
+
app.use((_req, res, next) => {
|
|
44
|
+
res.header('Access-Control-Allow-Origin', '*');
|
|
45
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
|
|
46
|
+
res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
|
|
47
|
+
next();
|
|
48
|
+
});
|
|
30
49
|
// compression
|
|
31
50
|
app.use(require('@umijs/bundler-webpack/compiled/compression')());
|
|
32
51
|
// TODO: headers
|
|
@@ -150,7 +169,7 @@ function createServer(opts) {
|
|
|
150
169
|
const port = opts.port || 8000;
|
|
151
170
|
server.listen(port, () => {
|
|
152
171
|
const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
|
|
153
|
-
utils_1.logger.ready(`App listening at http://${host}:${port}`);
|
|
172
|
+
utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`http://${host}:${port}`)}`);
|
|
154
173
|
});
|
|
155
174
|
return server;
|
|
156
175
|
});
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { ImportDeclaration,
|
|
1
|
+
import type { ImportDeclaration, ModuleItem, TsType } from '@swc/core';
|
|
2
2
|
import Visitor from '@swc/core/Visitor';
|
|
3
3
|
declare class AutoCSSModule extends Visitor {
|
|
4
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;
|
|
5
11
|
visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
|
|
6
|
-
visitVariableDeclaration(expression: VariableDeclaration): VariableDeclaration;
|
|
7
12
|
}
|
|
8
13
|
export default AutoCSSModule;
|
|
@@ -4,32 +4,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
|
|
7
|
-
const
|
|
8
|
-
const CSS_EXT_NAMES = ['.css', '.less', '.sass', '.scss', '.stylus', '.styl'];
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
9
8
|
class AutoCSSModule extends Visitor_1.default {
|
|
10
9
|
visitTsType(expression) {
|
|
11
10
|
return expression;
|
|
12
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* call path:
|
|
14
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
15
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
16
|
+
*/
|
|
17
|
+
visitModuleItem(n) {
|
|
18
|
+
if (n.type === 'ImportDeclaration') {
|
|
19
|
+
return this.visitImportDeclaration(n);
|
|
20
|
+
}
|
|
21
|
+
return n;
|
|
22
|
+
}
|
|
13
23
|
visitImportDeclaration(expression) {
|
|
14
24
|
const { specifiers, source } = expression;
|
|
15
25
|
const { value } = source;
|
|
16
|
-
if (specifiers.length &&
|
|
26
|
+
if (specifiers.length && (0, utils_1.isStyleFile)({ filename: value })) {
|
|
17
27
|
return Object.assign(Object.assign({}, expression), { source: Object.assign(Object.assign({}, source), { value: `${value}?modules` }) });
|
|
18
28
|
}
|
|
19
29
|
return expression;
|
|
20
30
|
}
|
|
21
|
-
visitVariableDeclaration(expression) {
|
|
22
|
-
const { declarations } = expression;
|
|
23
|
-
if (declarations.length &&
|
|
24
|
-
declarations[0].init &&
|
|
25
|
-
declarations[0].init.type === 'AwaitExpression' &&
|
|
26
|
-
declarations[0].init.argument.type === 'CallExpression' &&
|
|
27
|
-
declarations[0].init.argument.arguments[0].expression.type ===
|
|
28
|
-
'StringLiteral' &&
|
|
29
|
-
CSS_EXT_NAMES.includes((0, path_1.extname)(declarations[0].init.argument.arguments[0].expression.value))) {
|
|
30
|
-
declarations[0].init.argument.arguments[0].expression.value = `${declarations[0].init.argument.arguments[0].expression.value}?modules`;
|
|
31
|
-
}
|
|
32
|
-
return expression;
|
|
33
|
-
}
|
|
34
31
|
}
|
|
35
32
|
exports.default = AutoCSSModule;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
function addLastSlash(path) {
|
|
10
|
+
return path.endsWith('/') ? path : `${path}/`;
|
|
11
|
+
}
|
|
12
|
+
class LockCoreJS extends Visitor_1.default {
|
|
13
|
+
visitImportDeclaration(expression) {
|
|
14
|
+
const { source } = expression;
|
|
15
|
+
let { value, type } = source;
|
|
16
|
+
if (type === 'StringLiteral' && value.startsWith('core-js/')) {
|
|
17
|
+
value = value.replace(/^core-js\//, addLastSlash((0, utils_1.winPath)((0, path_1.dirname)(require.resolve('core-js/package.json')))));
|
|
18
|
+
return Object.assign(Object.assign({}, expression), { source: Object.assign(Object.assign({}, source), { value }) });
|
|
19
|
+
}
|
|
20
|
+
return expression;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = LockCoreJS;
|