@umijs/bundler-webpack 4.0.0-beta.7 → 4.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/compiled/autoprefixer/browserslist/index.d.ts +11 -7
  2. package/compiled/autoprefixer/index.js +3 -3
  3. package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
  4. package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
  5. package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
  6. package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
  7. package/compiled/autoprefixer/postcss/lib/declaration.d.ts +1 -1
  8. package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
  9. package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
  10. package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
  11. package/compiled/autoprefixer/postcss/lib/node.d.ts +36 -2
  12. package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
  13. package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
  14. package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
  15. package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
  16. package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
  17. package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
  18. package/compiled/babel-loader/index.js +2 -2
  19. package/compiled/copy-webpack-plugin/576.index.js +1171 -0
  20. package/compiled/copy-webpack-plugin/index.js +16 -10
  21. package/compiled/copy-webpack-plugin/package.json +1 -1
  22. package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
  23. package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
  24. package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
  25. package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
  26. package/compiled/cssnano/index.js +12 -11
  27. package/compiled/express/index.js +57 -74
  28. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  29. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  30. package/compiled/fork-ts-checker-webpack-plugin/index.js +48 -0
  31. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  32. package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
  33. package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
  34. package/compiled/http-proxy-middleware/index.js +10 -10
  35. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
  36. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
  37. package/compiled/mini-css-extract-plugin/index.js +8103 -7617
  38. package/compiled/mini-css-extract-plugin/loader.js +177 -54
  39. package/compiled/mini-css-extract-plugin/package.json +1 -1
  40. package/compiled/mini-css-extract-plugin/utils.js +83 -24
  41. package/compiled/postcss-loader/index.js +1 -1
  42. package/compiled/react-refresh/index.js +3 -3
  43. package/compiled/sass-loader/index.js +1 -1
  44. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  45. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  46. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  47. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  48. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  49. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  50. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  51. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  52. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  53. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  54. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  55. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  56. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  57. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  58. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  59. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  60. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  61. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  62. package/compiled/schema-utils/index.js +8 -2
  63. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  64. package/compiled/style-loader/index.js +1 -1
  65. package/compiled/terser/index.js +1 -1
  66. package/compiled/terser-webpack-plugin/index.js +393 -517
  67. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  68. package/compiled/terser-webpack-plugin/minify.js +10 -3
  69. package/compiled/terser-webpack-plugin/package.json +1 -1
  70. package/compiled/terser-webpack-plugin/types/index.d.ts +183 -149
  71. package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
  72. package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -15
  73. package/compiled/terser-webpack-plugin/utils.js +118 -25
  74. package/compiled/webpack/index.js +10464 -5286
  75. package/compiled/webpack-dev-middleware/index.js +11 -5
  76. package/compiled/webpack-dev-middleware/package.json +1 -1
  77. package/compiled/webpack-manifest-plugin/LICENSE +21 -0
  78. package/compiled/webpack-manifest-plugin/index.js +1 -0
  79. package/compiled/webpack-manifest-plugin/package.json +1 -0
  80. package/compiled/webpack-sources/index.js +1 -1
  81. package/compiled/ws/index.d.ts +1 -2
  82. package/compiled/ws/index.js +1 -1
  83. package/dist/build.d.ts +5 -3
  84. package/dist/build.js +2 -1
  85. package/dist/cli.js +4 -7
  86. package/dist/config/assetRules.js +6 -2
  87. package/dist/config/config.d.ts +7 -2
  88. package/dist/config/config.js +50 -8
  89. package/dist/config/cssRules.js +1 -1
  90. package/dist/config/detectDeadCode.d.ts +12 -0
  91. package/dist/config/detectDeadCode.js +120 -0
  92. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  93. package/dist/config/detectDeadCodePlugin.js +71 -0
  94. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  95. package/dist/config/forkTSCheckerPlugin.js +34 -0
  96. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  97. package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
  98. package/dist/config/javaScriptRules.d.ts +1 -0
  99. package/dist/config/javaScriptRules.js +32 -21
  100. package/dist/config/manifestPlugin.d.ts +11 -0
  101. package/dist/config/manifestPlugin.js +25 -0
  102. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  103. package/dist/config/miniCSSExtractPlugin.js +2 -3
  104. package/dist/config/svgRules.d.ts +1 -0
  105. package/dist/config/svgRules.js +12 -11
  106. package/dist/constants.d.ts +3 -0
  107. package/dist/constants.js +4 -1
  108. package/dist/dev.d.ts +4 -2
  109. package/dist/dev.js +41 -11
  110. package/dist/loader/svgr.d.ts +4 -0
  111. package/dist/loader/svgr.js +67 -0
  112. package/dist/loader/swc.d.ts +4 -0
  113. package/dist/loader/swc.js +79 -0
  114. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  115. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  116. package/dist/requireHook.js +1 -1
  117. package/dist/schema.js +13 -5
  118. package/dist/server/server.js +20 -1
  119. package/dist/server/ws.d.ts +1 -1
  120. package/dist/server/ws.js +1 -1
  121. package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
  122. package/dist/swcPlugins/autoCSSModules.js +13 -16
  123. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  124. package/dist/swcPlugins/lockCoreJS.js +23 -0
  125. package/dist/types.d.ts +15 -0
  126. package/dist/utils/depMatch.js +1 -1
  127. package/package.json +60 -55
  128. package/compiled/@svgr/webpack/.svgo.yml +0 -75
  129. package/compiled/@svgr/webpack/LICENSE +0 -7
  130. package/compiled/@svgr/webpack/index.js +0 -343
  131. package/compiled/@svgr/webpack/package.json +0 -1
  132. package/compiled/swc-loader/LICENSE +0 -25
  133. package/compiled/swc-loader/index.js +0 -1
  134. package/compiled/swc-loader/package.json +0 -1
@@ -9,3 +9,6 @@ export declare enum MESSAGE_TYPE {
9
9
  stillOk = "still-ok",
10
10
  invalid = "invalid"
11
11
  }
12
+ export declare const DEFAULT_BROWSER_TARGETS: {
13
+ chrome: number;
14
+ };
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
- interface IOpts {
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,37 +14,63 @@ 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 _b;
25
+ var _a, _b, _c, _d, _e;
26
+ var _f;
25
27
  return __awaiter(this, void 0, void 0, function* () {
26
- const mfsu = new mfsu_1.MFSU({
27
- implementor: webpack_1.default,
28
- buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
29
- });
28
+ const enableMFSU = opts.config.mfsu !== false;
29
+ let mfsu = null;
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
+ }
34
+ mfsu = new mfsu_1.MFSU({
35
+ implementor: webpack_1.default,
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
+ },
51
+ });
52
+ }
30
53
  const webpackConfig = yield (0, config_1.getConfig)({
31
54
  cwd: opts.cwd,
32
55
  env: types_1.Env.development,
33
56
  entry: opts.entry,
34
57
  userConfig: opts.config,
58
+ babelPreset: opts.babelPreset,
35
59
  extraBabelPlugins: [
36
60
  ...(opts.beforeBabelPlugins || []),
37
- ...mfsu.getBabelPlugins(),
61
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
38
62
  ...(opts.extraBabelPlugins || []),
39
63
  ],
40
64
  extraBabelPresets: [
41
65
  ...(opts.beforeBabelPresets || []),
42
66
  ...(opts.extraBabelPresets || []),
43
67
  ],
68
+ extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
44
69
  chainWebpack: opts.chainWebpack,
45
70
  modifyWebpackConfig: opts.modifyWebpackConfig,
46
71
  hmr: true,
47
72
  analyze: process.env.ANALYZE,
73
+ cache: opts.cache,
48
74
  });
49
75
  const depConfig = yield (0, config_1.getConfig)({
50
76
  cwd: opts.cwd,
@@ -54,23 +80,27 @@ function dev(opts) {
54
80
  hash: true,
55
81
  staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
56
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
+ },
57
87
  });
58
- (_b = webpackConfig.resolve).alias || (_b.alias = {});
88
+ (_f = webpackConfig.resolve).alias || (_f.alias = {});
59
89
  // TODO: REMOVE ME
60
90
  ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
61
91
  // @ts-ignore
62
92
  webpackConfig.resolve.alias[dep] = require.resolve(dep);
63
93
  });
64
- mfsu.setWebpackConfig({
94
+ yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
65
95
  config: webpackConfig,
66
96
  depConfig: depConfig,
67
- });
97
+ }));
68
98
  yield (0, server_1.createServer)({
69
99
  webpackConfig,
70
100
  userConfig: opts.config,
71
101
  cwd: opts.cwd,
72
102
  beforeMiddlewares: [
73
- ...mfsu.getMiddlewares(),
103
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getMiddlewares()) || []),
74
104
  ...(opts.beforeMiddlewares || []),
75
105
  ],
76
106
  port: opts.port,
@@ -0,0 +1,4 @@
1
+ import { Config } from '@svgr/core';
2
+ import type { LoaderContext } from '../../compiled/webpack';
3
+ declare function svgrLoader(this: LoaderContext<Config>, contents: string): void;
4
+ export default svgrLoader;
@@ -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,4 @@
1
+ import type { LoaderContext } from '../../compiled/webpack';
2
+ import { SwcOptions } from '../types';
3
+ declare function swcLoader(this: LoaderContext<SwcOptions>, contents: string): void;
4
+ export default swcLoader;
@@ -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,4 @@
1
+ import type { Compiler } from '@umijs/bundler-webpack/compiled/webpack';
2
+ export declare class RuntimePublicPathPlugin {
3
+ apply(compiler: Compiler): void;
4
+ }
@@ -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;
@@ -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('/').unshift();
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(),
@@ -34,30 +35,37 @@ function getSchemas() {
34
35
  cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, 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().pattern(/.+/, [
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(),
@@ -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,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Server } from 'http';
3
- import WebSocket from 'ws';
3
+ import WebSocket from '../../compiled/ws';
4
4
  export declare function createWebSocketServer(server: Server): {
5
5
  send(message: string): void;
6
6
  wss: WebSocket.Server;
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, TsType, VariableDeclaration } from '@swc/core';
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 path_1 = require("path");
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 && CSS_EXT_NAMES.includes((0, path_1.extname)(value))) {
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,6 @@
1
+ import { ImportDeclaration } from '@swc/core';
2
+ import Visitor from '@swc/core/Visitor';
3
+ declare class LockCoreJS extends Visitor {
4
+ visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
5
+ }
6
+ export default LockCoreJS;
@@ -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;
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Config as SwcConfig } from '@swc/core';
1
2
  import type { Options as ProxyOptions } from '../compiled/http-proxy-middleware';
2
3
  import { Configuration } from '../compiled/webpack';
3
4
  import Config from '../compiled/webpack-5-chain';
@@ -31,9 +32,18 @@ declare type WebpackConfig = Required<Configuration>;
31
32
  declare type IBabelPlugin = Function | string | [string, {
32
33
  [key: string]: any;
33
34
  }];
35
+ export interface DeadCodeParams {
36
+ patterns?: string[];
37
+ exclude?: string[];
38
+ failOnHint?: boolean;
39
+ detectUnusedFiles?: boolean;
40
+ detectUnusedExport?: boolean;
41
+ context?: string;
42
+ }
34
43
  export interface IConfig {
35
44
  alias?: Record<string, string>;
36
45
  autoCSSModules?: boolean;
46
+ base?: string;
37
47
  chainWebpack?: Function;
38
48
  copy?: ICopy[] | string[];
39
49
  cssLoader?: {
@@ -51,6 +61,7 @@ export interface IConfig {
51
61
  };
52
62
  depTranspiler?: Transpiler;
53
63
  devtool?: Config.DevTool;
64
+ deadCode?: DeadCodeParams;
54
65
  externals?: WebpackConfig['externals'];
55
66
  esm?: {
56
67
  [key: string]: any;
@@ -97,4 +108,8 @@ export interface IConfig {
97
108
  writeToDisk?: boolean;
98
109
  [key: string]: any;
99
110
  }
111
+ export interface SwcOptions extends SwcConfig {
112
+ sync?: boolean;
113
+ parseMap?: boolean;
114
+ }
100
115
  export {};
@@ -15,7 +15,7 @@ function isMatch(opts) {
15
15
  return !!cache.get(dir);
16
16
  }
17
17
  else {
18
- const pkgPath = utils_1.pkgUp.sync({ cwd: opts.path });
18
+ const pkgPath = utils_1.pkgUp.pkgUpSync({ cwd: opts.path });
19
19
  let ret;
20
20
  if (!pkgPath) {
21
21
  ret = false;