@umijs/bundler-webpack 4.0.0-beta.7 → 4.0.0-canary.202200505.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/client/client.js +65 -37
- package/client/constants.js +9 -0
- package/compiled/autoprefixer/browserslist/index.d.ts +13 -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 +2 -2
- 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 +38 -4
- 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/939.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/cssnano/package.json +1 -1
- package/compiled/express.d.ts +2 -0
- 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 +42 -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 +7970 -7445
- package/compiled/mini-css-extract-plugin/loader.js +179 -54
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +85 -24
- package/compiled/postcss-loader/index.js +1 -1
- package/compiled/react-refresh/LICENSE +21 -0
- package/compiled/react-refresh/index.js +9 -7
- package/compiled/react-refresh/package.json +1 -0
- 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/BasicEffectRulePlugin.js +1 -0
- package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
- package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
- package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
- package/compiled/webpack/RuleSetCompiler.js +1 -0
- package/compiled/webpack/UseEffectRulePlugin.js +1 -0
- package/compiled/webpack/deepImports.json +6 -1
- package/compiled/webpack/index.js +13409 -5746
- package/compiled/webpack/types.d.ts +606 -171
- package/compiled/webpack-dev-middleware/index.js +11 -5
- package/compiled/webpack-dev-middleware/package.json +1 -1
- package/compiled/{tapable → webpack-manifest-plugin}/LICENSE +2 -2
- 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 +6 -3
- package/dist/build.js +48 -56
- package/dist/cli.js +10 -22
- package/dist/client/client.js +57 -51
- package/dist/config/_sampleFeature.js +6 -17
- package/dist/config/assetRules.js +44 -51
- package/dist/config/bundleAnalyzerPlugin.js +12 -23
- package/dist/config/compressPlugin.js +70 -64
- package/dist/config/config.d.ts +9 -2
- package/dist/config/config.js +184 -144
- package/dist/config/copyPlugin.js +29 -40
- package/dist/config/cssRules.js +93 -83
- package/dist/config/definePlugin.js +11 -19
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +120 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +70 -0
- package/dist/config/fastRefreshPlugin.js +11 -22
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +23 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +31 -0
- package/dist/config/ignorePlugin.js +10 -21
- package/dist/config/javaScriptRules.d.ts +2 -0
- package/dist/config/javaScriptRules.js +153 -131
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +17 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
- package/dist/config/miniCSSExtractPlugin.js +12 -24
- package/dist/config/nodePolyfill.js +14 -20
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +14 -0
- package/dist/config/progressPlugin.js +7 -18
- package/dist/config/purgecssWebpackPlugin.js +15 -26
- package/dist/config/speedMeasureWebpackPlugin.js +12 -23
- package/dist/config/svgRules.d.ts +1 -0
- package/dist/config/svgRules.js +45 -48
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +10 -1
- package/dist/dev.d.ts +8 -2
- package/dist/dev.js +117 -66
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -1
- package/dist/loader/svgr.d.ts +4 -0
- package/dist/loader/svgr.js +58 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +74 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -36
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +73 -0
- package/dist/plugins/ProgressPlugin.js +2 -2
- 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 +23 -11
- package/dist/server/server.d.ts +2 -1
- package/dist/server/server.js +165 -130
- package/dist/server/ws.d.ts +6 -3
- package/dist/server/ws.js +1 -1
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +16 -17
- 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 +19 -0
- package/dist/types.js +1 -0
- package/dist/utils/depMatch.js +1 -1
- package/dist/utils/getEsBuildTarget.d.ts +5 -0
- package/dist/utils/getEsBuildTarget.js +12 -0
- package/package.json +68 -67
- package/compiled/@svgr/webpack/.svgo.yml +0 -75
- package/compiled/@svgr/webpack/LICENSE +0 -7
- package/compiled/@svgr/webpack/index.js +0 -343
- package/compiled/@svgr/webpack/package.json +0 -1
- package/compiled/css-loader/LICENSE +0 -20
- package/compiled/css-loader/api.js +0 -102
- package/compiled/css-loader/getUrl.js +0 -29
- package/compiled/css-loader/index.js +0 -2
- package/compiled/css-loader/noSourceMaps.js +0 -5
- package/compiled/css-loader/package.json +0 -1
- package/compiled/css-loader/sourceMaps.js +0 -22
- package/compiled/express/LICENSE +0 -24
- package/compiled/express/body-parser/index.d.ts +0 -104
- package/compiled/express/connect/index.d.ts +0 -93
- package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
- package/compiled/express/index.d.ts +0 -133
- package/compiled/express/index.js +0 -338
- package/compiled/express/mime/index.d.ts +0 -35
- package/compiled/express/package.json +0 -1
- package/compiled/express/qs/index.d.ts +0 -62
- package/compiled/express/range-parser/index.d.ts +0 -35
- package/compiled/express/serve-static/index.d.ts +0 -108
- package/compiled/less/index.js +0 -31
- package/compiled/less/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/compiled/tapable/index.js +0 -1
- package/compiled/tapable/package.json +0 -1
- package/compiled/tapable/tapable.d.ts +0 -116
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParcelCSSMinifyPlugin = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const buffer_1 = require("buffer");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const webpack_sources_1 = require("../../compiled/webpack-sources");
|
|
8
|
+
const pkgPath = (0, path_1.join)(__dirname, '../../package.json');
|
|
9
|
+
const pkg = require(pkgPath);
|
|
10
|
+
const PLUGIN_NAME = 'parcel-css-minify-plugin';
|
|
11
|
+
const CSS_FILE_REG = /\.css(?:\?.*)?$/i;
|
|
12
|
+
class ParcelCSSMinifyPlugin {
|
|
13
|
+
constructor(opts = {}) {
|
|
14
|
+
this.options = opts;
|
|
15
|
+
}
|
|
16
|
+
apply(compiler) {
|
|
17
|
+
const meta = JSON.stringify({
|
|
18
|
+
name: pkg.name,
|
|
19
|
+
version: pkg.version,
|
|
20
|
+
options: this.options,
|
|
21
|
+
});
|
|
22
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
23
|
+
compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
|
|
24
|
+
compilation.hooks.processAssets.tapPromise({
|
|
25
|
+
name: PLUGIN_NAME,
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
|
|
28
|
+
additionalAssets: true,
|
|
29
|
+
}, async () => await this.transformAssets(compilation));
|
|
30
|
+
compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
|
|
31
|
+
statsPrinter.hooks.print
|
|
32
|
+
.for('asset.info.minimized')
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
.tap(PLUGIN_NAME, (minimized, { green, formatFlag }) => {
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
return minimized ? green(formatFlag('minimized')) : undefined;
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async transformAssets(compilation) {
|
|
42
|
+
const { options: { devtool }, } = compilation.compiler;
|
|
43
|
+
const sourcemap = this.options.sourceMap === undefined
|
|
44
|
+
? (devtool && devtool.includes('source-map'))
|
|
45
|
+
: this.options.sourceMap;
|
|
46
|
+
const assets = compilation.getAssets().filter((asset) => {
|
|
47
|
+
return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
|
|
48
|
+
});
|
|
49
|
+
await Promise.all(assets.map(async (asset) => {
|
|
50
|
+
const { source, map } = asset.source.sourceAndMap();
|
|
51
|
+
const sourceAsString = source.toString();
|
|
52
|
+
const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
|
|
53
|
+
const { transform } = (0, utils_1.importLazy)('@parcel/css');
|
|
54
|
+
const result = await transform({
|
|
55
|
+
filename: asset.name,
|
|
56
|
+
code,
|
|
57
|
+
minify: true,
|
|
58
|
+
sourceMap: sourcemap,
|
|
59
|
+
...this.options,
|
|
60
|
+
});
|
|
61
|
+
const codeString = result.code.toString();
|
|
62
|
+
compilation.updateAsset(asset.name,
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
sourcemap
|
|
65
|
+
? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
|
|
66
|
+
: new webpack_sources_1.RawSource(codeString), {
|
|
67
|
+
...asset.info,
|
|
68
|
+
minimized: true,
|
|
69
|
+
});
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;
|
|
@@ -13,7 +13,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
|
|
|
13
13
|
}
|
|
14
14
|
apply(compiler) {
|
|
15
15
|
compiler.hooks.invalid.tap(PLUGIN_NAME, () => {
|
|
16
|
-
utils_1.logger.wait('
|
|
16
|
+
utils_1.logger.wait('Compiling...');
|
|
17
17
|
});
|
|
18
18
|
compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
|
|
19
19
|
const { errors, warnings } = stats.toJson({
|
|
@@ -33,7 +33,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
|
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
const prefix = this.options.name ? `${this.options.name} ` : '';
|
|
36
|
-
utils_1.logger.event(`${prefix}
|
|
36
|
+
utils_1.logger.event(`${prefix}Compiled successfully in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -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 = (globalThis || 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,42 +32,53 @@ 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(),
|
|
37
|
+
deadCode: (Joi) => Joi.object(),
|
|
36
38
|
define: (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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
extraBabelPlugins: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
|
|
45
|
-
extraBabelPresets: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
|
|
41
|
+
esm: (Joi) => Joi.object(),
|
|
42
|
+
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
43
|
+
extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
|
|
44
|
+
extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
45
|
+
extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
46
46
|
extraPostCSSPlugins: (Joi) => Joi.array(),
|
|
47
47
|
fastRefresh: (Joi) => Joi.boolean(),
|
|
48
|
+
forkTSChecker: (Joi) => Joi.object(),
|
|
48
49
|
hash: (Joi) => Joi.boolean(),
|
|
50
|
+
https: (Joi) => Joi.object(),
|
|
49
51
|
ignoreMomentLocale: (Joi) => Joi.boolean(),
|
|
52
|
+
inlineLimit: (Joi) => Joi.number(),
|
|
50
53
|
jsMinifier: (Joi) => Joi.string().valid(types_1.JSMinifier.esbuild, types_1.JSMinifier.swc, types_1.JSMinifier.terser, types_1.JSMinifier.uglifyJs, types_1.JSMinifier.none),
|
|
51
54
|
jsMinifierOptions: (Joi) => Joi.object(),
|
|
52
55
|
lessLoader: (Joi) => Joi.object(),
|
|
56
|
+
manifest: (Joi) => Joi.object(),
|
|
57
|
+
mdx: (Joi) => Joi.object({
|
|
58
|
+
loader: Joi.string(),
|
|
59
|
+
loaderOptions: Joi.object(),
|
|
60
|
+
}),
|
|
53
61
|
mfsu: (Joi) => Joi.alternatives(Joi.object({
|
|
62
|
+
cacheDirectory: Joi.string(),
|
|
63
|
+
chainWebpack: Joi.function(),
|
|
54
64
|
esbuild: Joi.boolean(),
|
|
65
|
+
mfName: Joi.string(),
|
|
66
|
+
runtimePublicPath: Joi.boolean(),
|
|
55
67
|
}), Joi.boolean()),
|
|
56
68
|
outputPath: (Joi) => Joi.string(),
|
|
57
69
|
postcssLoader: (Joi) => Joi.object(),
|
|
58
70
|
proxy: (Joi) => Joi.object(),
|
|
59
71
|
publicPath: (Joi) => Joi.string(),
|
|
60
72
|
purgeCSS: (Joi) => Joi.object(),
|
|
73
|
+
runtimePublicPath: (Joi) => Joi.object(),
|
|
61
74
|
sassLoader: (Joi) => Joi.object(),
|
|
62
75
|
srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
|
|
63
76
|
styleLoader: (Joi) => Joi.object(),
|
|
64
|
-
svgr: (Joi) => Joi.object(),
|
|
65
77
|
svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
|
|
78
|
+
svgr: (Joi) => Joi.object(),
|
|
66
79
|
targets: (Joi) => Joi.object(),
|
|
67
|
-
writeToDisk: (Joi) => Joi.boolean(),
|
|
68
|
-
esm: (Joi) => Joi.object(),
|
|
69
80
|
theme: (Joi) => Joi.object(),
|
|
81
|
+
writeToDisk: (Joi) => Joi.boolean(),
|
|
70
82
|
};
|
|
71
83
|
}
|
|
72
84
|
exports.getSchemas = getSchemas;
|
package/dist/server/server.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface IOpts {
|
|
|
11
11
|
beforeMiddlewares?: any[];
|
|
12
12
|
afterMiddlewares?: any[];
|
|
13
13
|
onDevCompileDone?: Function;
|
|
14
|
+
onProgress?: Function;
|
|
14
15
|
}
|
|
15
|
-
export declare function createServer(opts: IOpts): Promise<http.Server>;
|
|
16
|
+
export declare function createServer(opts: IOpts): Promise<http.Server | import("https").Server | null>;
|
|
16
17
|
export {};
|
package/dist/server/server.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.createServer = void 0;
|
|
16
|
-
const
|
|
7
|
+
const bundler_utils_1 = require("@umijs/bundler-utils");
|
|
8
|
+
const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
|
|
17
9
|
const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
|
|
18
10
|
const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
|
|
19
11
|
const utils_1 = require("@umijs/utils");
|
|
@@ -22,137 +14,180 @@ const http_1 = __importDefault(require("http"));
|
|
|
22
14
|
const path_1 = require("path");
|
|
23
15
|
const constants_1 = require("../constants");
|
|
24
16
|
const ws_1 = require("./ws");
|
|
25
|
-
function createServer(opts) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
17
|
+
async function createServer(opts) {
|
|
18
|
+
const { webpackConfig, userConfig } = opts;
|
|
19
|
+
const { proxy } = userConfig;
|
|
20
|
+
const app = (0, express_1.default)();
|
|
21
|
+
// cros
|
|
22
|
+
app.use((_req, res, next) => {
|
|
23
|
+
res.header('Access-Control-Allow-Origin', '*');
|
|
24
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
|
|
25
|
+
res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
|
|
26
|
+
next();
|
|
27
|
+
});
|
|
28
|
+
// compression
|
|
29
|
+
app.use(require('@umijs/bundler-webpack/compiled/compression')());
|
|
30
|
+
// TODO: headers
|
|
31
|
+
// before middlewares
|
|
32
|
+
(opts.beforeMiddlewares || []).forEach((m) => app.use(m));
|
|
33
|
+
// TODO: add to before middleware
|
|
34
|
+
app.use((req, res, next) => {
|
|
35
|
+
if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
|
|
36
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
37
|
+
(0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
next();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// webpack dev middleware
|
|
44
|
+
const configs = Array.isArray(webpackConfig)
|
|
45
|
+
? webpackConfig
|
|
46
|
+
: [webpackConfig];
|
|
47
|
+
const progresses = [];
|
|
48
|
+
if (opts.onProgress) {
|
|
49
|
+
configs.forEach((config) => {
|
|
50
|
+
const progress = {
|
|
51
|
+
percent: 0,
|
|
52
|
+
status: 'waiting',
|
|
53
|
+
};
|
|
54
|
+
progresses.push(progress);
|
|
55
|
+
config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
|
|
56
|
+
progress.percent = percent;
|
|
57
|
+
progress.status = msg;
|
|
58
|
+
opts.onProgress({ progresses });
|
|
59
|
+
}));
|
|
44
60
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
}
|
|
62
|
+
const compiler = (0, webpack_1.default)(configs);
|
|
63
|
+
const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
|
|
64
|
+
const compilerMiddleware = webpackDevMiddleware(compiler, {
|
|
65
|
+
publicPath: userConfig.publicPath || '/',
|
|
66
|
+
writeToDisk: userConfig.writeToDisk,
|
|
67
|
+
stats: 'none',
|
|
68
|
+
// watchOptions: { ignored }
|
|
69
|
+
});
|
|
70
|
+
app.use(compilerMiddleware);
|
|
71
|
+
// hmr hooks
|
|
72
|
+
let stats;
|
|
73
|
+
let isFirstCompile = true;
|
|
74
|
+
compiler.compilers.forEach(addHooks);
|
|
75
|
+
function addHooks(compiler) {
|
|
76
|
+
compiler.hooks.invalid.tap('server', () => {
|
|
77
|
+
sendMessage(constants_1.MESSAGE_TYPE.invalid);
|
|
53
78
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
compiler.hooks.done.tap('server', (_stats) => {
|
|
64
|
-
var _a;
|
|
65
|
-
stats = _stats;
|
|
66
|
-
sendStats(getStats(stats));
|
|
67
|
-
(_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
|
|
68
|
-
stats,
|
|
69
|
-
isFirstCompile,
|
|
70
|
-
time: stats.endTime - stats.startTime,
|
|
71
|
-
});
|
|
72
|
-
isFirstCompile = false;
|
|
79
|
+
compiler.hooks.done.tap('server', (_stats) => {
|
|
80
|
+
var _a;
|
|
81
|
+
stats = _stats;
|
|
82
|
+
sendStats(getStats(stats));
|
|
83
|
+
(_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
|
|
84
|
+
stats,
|
|
85
|
+
isFirstCompile,
|
|
86
|
+
time: stats.endTime - stats.startTime,
|
|
73
87
|
});
|
|
88
|
+
isFirstCompile = false;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function sendStats(stats, force, sender) {
|
|
92
|
+
const shouldEmit = !force &&
|
|
93
|
+
stats &&
|
|
94
|
+
(!stats.errors || stats.errors.length === 0) &&
|
|
95
|
+
(!stats.warnings || stats.warnings.length === 0) &&
|
|
96
|
+
stats.assets &&
|
|
97
|
+
stats.assets.every((asset) => !asset.emitted);
|
|
98
|
+
if (shouldEmit) {
|
|
99
|
+
sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
|
|
100
|
+
return;
|
|
74
101
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
(
|
|
80
|
-
stats.assets &&
|
|
81
|
-
stats.assets.every((asset) => !asset.emitted);
|
|
82
|
-
if (shouldEmit) {
|
|
83
|
-
sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
|
|
84
|
-
return;
|
|
102
|
+
sendMessage(constants_1.MESSAGE_TYPE.hash, stats.hash, sender);
|
|
103
|
+
if ((stats.errors && stats.errors.length > 0) ||
|
|
104
|
+
(stats.warnings && stats.warnings.length > 0)) {
|
|
105
|
+
if (stats.warnings && stats.warnings.length > 0) {
|
|
106
|
+
sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
|
|
85
107
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
(stats.warnings && stats.warnings.length > 0)) {
|
|
89
|
-
if (stats.warnings && stats.warnings.length > 0) {
|
|
90
|
-
sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
|
|
91
|
-
}
|
|
92
|
-
if (stats.errors && stats.errors.length > 0) {
|
|
93
|
-
sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
|
|
94
|
-
}
|
|
108
|
+
if (stats.errors && stats.errors.length > 0) {
|
|
109
|
+
sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
|
|
95
110
|
}
|
|
96
|
-
else {
|
|
97
|
-
sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function getStats(stats) {
|
|
101
|
-
return stats.toJson({
|
|
102
|
-
all: false,
|
|
103
|
-
hash: true,
|
|
104
|
-
assets: true,
|
|
105
|
-
warnings: true,
|
|
106
|
-
errors: true,
|
|
107
|
-
errorDetails: false,
|
|
108
|
-
});
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
(
|
|
112
|
+
else {
|
|
113
|
+
sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
|
|
112
114
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// history fallback
|
|
123
|
-
app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
|
|
124
|
-
index: '/',
|
|
125
|
-
}));
|
|
126
|
-
// hmr reconnect ping
|
|
127
|
-
app.use('/__umi_ping', (_, res) => {
|
|
128
|
-
res.end('pong');
|
|
115
|
+
}
|
|
116
|
+
function getStats(stats) {
|
|
117
|
+
return stats.toJson({
|
|
118
|
+
all: false,
|
|
119
|
+
hash: true,
|
|
120
|
+
assets: true,
|
|
121
|
+
warnings: true,
|
|
122
|
+
errors: true,
|
|
123
|
+
errorDetails: false,
|
|
129
124
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
125
|
+
}
|
|
126
|
+
function sendMessage(type, data, sender) {
|
|
127
|
+
(sender || ws).send(JSON.stringify({ type, data }));
|
|
128
|
+
}
|
|
129
|
+
// mock
|
|
130
|
+
// proxy
|
|
131
|
+
if (proxy) {
|
|
132
|
+
Object.keys(proxy).forEach((key) => {
|
|
133
|
+
const proxyConfig = proxy[key];
|
|
134
|
+
const target = proxyConfig.target;
|
|
135
|
+
if (target) {
|
|
136
|
+
app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, {
|
|
137
|
+
...proxy[key],
|
|
138
|
+
// Add x-real-url in response header
|
|
139
|
+
onProxyRes(proxyRes, req) {
|
|
140
|
+
var _a;
|
|
141
|
+
proxyRes.headers['x-real-url'] =
|
|
142
|
+
((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
|
|
143
|
+
},
|
|
144
|
+
}));
|
|
141
145
|
}
|
|
142
146
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
147
|
+
}
|
|
148
|
+
// after middlewares
|
|
149
|
+
(opts.afterMiddlewares || []).forEach((m) => {
|
|
150
|
+
// TODO: FIXME
|
|
151
|
+
app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
|
|
152
|
+
});
|
|
153
|
+
// history fallback
|
|
154
|
+
app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
|
|
155
|
+
index: '/',
|
|
156
|
+
}));
|
|
157
|
+
// hmr reconnect ping
|
|
158
|
+
app.use('/__umi_ping', (_, res) => {
|
|
159
|
+
res.end('pong');
|
|
160
|
+
});
|
|
161
|
+
// index.html
|
|
162
|
+
// TODO: remove me
|
|
163
|
+
app.get('/', (_req, res, next) => {
|
|
164
|
+
res.set('Content-Type', 'text/html');
|
|
165
|
+
const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
|
|
166
|
+
if ((0, fs_1.existsSync)(htmlPath)) {
|
|
167
|
+
(0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
next();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const server = userConfig.https
|
|
174
|
+
? await (0, bundler_utils_1.createHttpsServer)(app, userConfig.https)
|
|
175
|
+
: http_1.default.createServer(app);
|
|
176
|
+
if (!server) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const ws = (0, ws_1.createWebSocketServer)(server);
|
|
180
|
+
ws.wss.on('connection', (socket) => {
|
|
181
|
+
if (stats) {
|
|
182
|
+
sendStats(getStats(stats), false, socket);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const protocol = userConfig.https ? 'https:' : 'http:';
|
|
186
|
+
const port = opts.port || 8000;
|
|
187
|
+
server.listen(port, () => {
|
|
188
|
+
const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
|
|
189
|
+
utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
|
|
156
190
|
});
|
|
191
|
+
return server;
|
|
157
192
|
}
|
|
158
193
|
exports.createServer = createServer;
|
package/dist/server/ws.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Server } from '
|
|
3
|
-
import
|
|
4
|
-
|
|
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): {
|
|
5
8
|
send(message: string): void;
|
|
6
9
|
wss: WebSocket.Server;
|
|
7
10
|
close(): void;
|
package/dist/server/ws.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createWebSocketServer = void 0;
|
|
7
7
|
const utils_1 = require("@umijs/utils");
|
|
8
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
|
+
const ws_1 = __importDefault(require("../../compiled/ws"));
|
|
9
9
|
function createWebSocketServer(server) {
|
|
10
10
|
const wss = new ws_1.default.Server({
|
|
11
11
|
noServer: true,
|
|
@@ -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,30 +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
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const changeImportFromString_1 = require("./changeImportFromString");
|
|
9
9
|
class AutoCSSModule extends Visitor_1.default {
|
|
10
10
|
visitTsType(expression) {
|
|
11
11
|
return expression;
|
|
12
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
|
+
}
|
|
13
24
|
visitImportDeclaration(expression) {
|
|
14
25
|
const { specifiers, source } = expression;
|
|
15
26
|
const { value } = source;
|
|
16
|
-
if (specifiers.length &&
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return expression;
|
|
20
|
-
}
|
|
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`;
|
|
27
|
+
if (specifiers.length && (0, utils_1.isStyleFile)({ filename: value })) {
|
|
28
|
+
const newImportFrom = `${value}?modules`;
|
|
29
|
+
(0, changeImportFromString_1.changeImportFromString)(expression, newImportFrom);
|
|
31
30
|
}
|
|
32
31
|
return expression;
|
|
33
32
|
}
|
|
@@ -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;
|