@umijs/bundler-webpack 4.0.0-beta.7 → 4.0.0-canary.20220316.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.
Files changed (151) 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/cssnano/package.json +1 -1
  28. package/compiled/express/index.js +57 -74
  29. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  30. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  31. package/compiled/fork-ts-checker-webpack-plugin/index.js +48 -0
  32. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  33. package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
  34. package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
  35. package/compiled/http-proxy-middleware/index.js +10 -10
  36. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
  37. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
  38. package/compiled/mini-css-extract-plugin/index.js +7970 -7445
  39. package/compiled/mini-css-extract-plugin/loader.js +179 -54
  40. package/compiled/mini-css-extract-plugin/package.json +1 -1
  41. package/compiled/mini-css-extract-plugin/utils.js +85 -24
  42. package/compiled/postcss-loader/index.js +1 -1
  43. package/compiled/react-refresh/index.js +3 -3
  44. package/compiled/sass-loader/index.js +1 -1
  45. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  46. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  47. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  48. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  49. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  50. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  51. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  52. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  53. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  54. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  55. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  56. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  57. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  58. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  59. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  60. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  61. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  62. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  63. package/compiled/schema-utils/index.js +8 -2
  64. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  65. package/compiled/style-loader/index.js +1 -1
  66. package/compiled/terser/index.js +1 -1
  67. package/compiled/terser-webpack-plugin/index.js +393 -517
  68. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  69. package/compiled/terser-webpack-plugin/minify.js +10 -3
  70. package/compiled/terser-webpack-plugin/package.json +1 -1
  71. package/compiled/terser-webpack-plugin/types/index.d.ts +183 -149
  72. package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
  73. package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -15
  74. package/compiled/terser-webpack-plugin/utils.js +118 -25
  75. package/compiled/webpack/index.js +11665 -5565
  76. package/compiled/webpack-dev-middleware/index.js +11 -5
  77. package/compiled/webpack-dev-middleware/package.json +1 -1
  78. package/compiled/webpack-manifest-plugin/LICENSE +21 -0
  79. package/compiled/webpack-manifest-plugin/index.js +1 -0
  80. package/compiled/webpack-manifest-plugin/package.json +1 -0
  81. package/compiled/webpack-sources/index.js +1 -1
  82. package/compiled/ws/index.d.ts +1 -2
  83. package/compiled/ws/index.js +1 -1
  84. package/dist/build.d.ts +5 -3
  85. package/dist/build.js +2 -1
  86. package/dist/cli.js +4 -7
  87. package/dist/client/client.js +5 -1
  88. package/dist/config/assetRules.js +6 -2
  89. package/dist/config/compressPlugin.js +6 -0
  90. package/dist/config/config.d.ts +7 -2
  91. package/dist/config/config.js +50 -8
  92. package/dist/config/cssRules.js +1 -1
  93. package/dist/config/detectDeadCode.d.ts +12 -0
  94. package/dist/config/detectDeadCode.js +120 -0
  95. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  96. package/dist/config/detectDeadCodePlugin.js +75 -0
  97. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  98. package/dist/config/forkTSCheckerPlugin.js +34 -0
  99. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  100. package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
  101. package/dist/config/javaScriptRules.d.ts +1 -0
  102. package/dist/config/javaScriptRules.js +34 -26
  103. package/dist/config/manifestPlugin.d.ts +11 -0
  104. package/dist/config/manifestPlugin.js +25 -0
  105. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  106. package/dist/config/miniCSSExtractPlugin.js +2 -3
  107. package/dist/config/svgRules.d.ts +1 -0
  108. package/dist/config/svgRules.js +12 -11
  109. package/dist/constants.d.ts +3 -0
  110. package/dist/constants.js +4 -1
  111. package/dist/dev.d.ts +4 -2
  112. package/dist/dev.js +41 -11
  113. package/dist/index.d.ts +3 -0
  114. package/dist/index.js +5 -1
  115. package/dist/loader/svgr.d.ts +4 -0
  116. package/dist/loader/svgr.js +67 -0
  117. package/dist/loader/swc.d.ts +4 -0
  118. package/dist/loader/swc.js +79 -0
  119. package/dist/plugins/ESBuildCSSMinifyPlugin.js +1 -3
  120. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  121. package/dist/plugins/ParcelCSSMinifyPlugin.js +75 -0
  122. package/dist/plugins/ProgressPlugin.js +2 -2
  123. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  124. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  125. package/dist/requireHook.js +1 -1
  126. package/dist/schema.js +17 -9
  127. package/dist/server/server.js +24 -2
  128. package/dist/server/ws.d.ts +1 -1
  129. package/dist/server/ws.js +1 -1
  130. package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
  131. package/dist/swcPlugins/autoCSSModules.js +13 -16
  132. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  133. package/dist/swcPlugins/lockCoreJS.js +23 -0
  134. package/dist/types.d.ts +16 -0
  135. package/dist/types.js +1 -0
  136. package/dist/utils/depMatch.js +1 -1
  137. package/package.json +63 -56
  138. package/compiled/@svgr/webpack/.svgo.yml +0 -75
  139. package/compiled/@svgr/webpack/LICENSE +0 -7
  140. package/compiled/@svgr/webpack/index.js +0 -343
  141. package/compiled/@svgr/webpack/package.json +0 -1
  142. package/compiled/css-loader/LICENSE +0 -20
  143. package/compiled/css-loader/api.js +0 -102
  144. package/compiled/css-loader/getUrl.js +0 -29
  145. package/compiled/css-loader/index.js +0 -2
  146. package/compiled/css-loader/noSourceMaps.js +0 -5
  147. package/compiled/css-loader/package.json +0 -1
  148. package/compiled/css-loader/sourceMaps.js +0 -22
  149. package/compiled/swc-loader/LICENSE +0 -25
  150. package/compiled/swc-loader/index.js +0 -1
  151. package/compiled/swc-loader/package.json +0 -1
@@ -13,24 +13,25 @@ exports.addSVGRules = void 0;
13
13
  function addSVGRules(opts) {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
15
  const { config, userConfig } = opts;
16
- const { svgr, svgo } = userConfig;
16
+ const { svgr, svgo = {} } = userConfig;
17
17
  if (svgr) {
18
- // https://react-svgr.com/docs/webpack/#handle-svg-in-css-sass-or-less
19
- // https://github.com/gregberge/svgr/issues/551#issuecomment-883073902
20
- // https://github.com/webpack/webpack/issues/9309
21
18
  const svgrRule = config.module.rule('svgr');
22
19
  svgrRule
23
20
  .test(/\.svg$/)
24
21
  .issuer(/\.[jt]sx?$/)
25
22
  .type('javascript/auto')
26
- .use('babel-loader')
27
- .loader(require.resolve('@umijs/bundler-webpack/compiled/babel-loader'))
28
- .end()
29
23
  .use('svgr-loader')
30
- .loader(require.resolve('@umijs/bundler-webpack/compiled/@svgr/webpack'))
31
- .options(Object.assign(Object.assign({ svgoConfig: {
32
- plugins: [{ removeViewBox: false }],
33
- } }, svgr), { svgo }))
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 }))
34
35
  .end()
35
36
  .use('url-loader')
36
37
  .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
@@ -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,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import type webpack from '../compiled/webpack';
1
2
  export type { RequestHandler } from '../compiled/express';
3
+ export type { Compiler, Stats } from '../compiled/webpack';
2
4
  export * from './build';
3
5
  export * from './config/config';
4
6
  export * from './dev';
5
7
  export * from './schema';
8
+ export { webpack };
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -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;
@@ -38,9 +38,7 @@ class ESBuildCSSMinifyPlugin {
38
38
  transformAssets(compilation) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  const { options: { devtool }, } = compilation.compiler;
41
- const sourcemap = this.options.sourcemap === undefined
42
- ? devtool && devtool
43
- : this.options.sourcemap;
41
+ const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
44
42
  const assets = compilation.getAssets().filter((asset) => {
45
43
  return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
46
44
  });
@@ -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,75 @@
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 utils_1 = require("@umijs/utils");
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 { transform } = (0, utils_1.importLazy)('@parcel/css');
64
+ const result = yield transform(Object.assign({ filename: asset.name, code, minify: true, sourceMap: sourcemap }, this.options));
65
+ const codeString = result.code.toString();
66
+ compilation.updateAsset(asset.name,
67
+ // @ts-ignore
68
+ sourcemap
69
+ ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
70
+ : new webpack_sources_1.RawSource(codeString), Object.assign(Object.assign({}, asset.info), { minimized: true }));
71
+ })));
72
+ });
73
+ }
74
+ }
75
+ 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('compiling...');
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}compiled successfully in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
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,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 = (globalThis || 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(),
@@ -31,42 +32,49 @@ 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
- 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
+ esm: (Joi) => Joi.object(),
42
+ externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
44
43
  extraBabelPlugins: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
45
44
  extraBabelPresets: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
46
45
  extraPostCSSPlugins: (Joi) => Joi.array(),
47
46
  fastRefresh: (Joi) => Joi.boolean(),
47
+ forkTSChecker: (Joi) => Joi.object(),
48
48
  hash: (Joi) => Joi.boolean(),
49
49
  ignoreMomentLocale: (Joi) => Joi.boolean(),
50
+ inlineLimit: (Joi) => Joi.number(),
50
51
  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
52
  jsMinifierOptions: (Joi) => Joi.object(),
52
53
  lessLoader: (Joi) => Joi.object(),
54
+ manifest: (Joi) => Joi.object(),
55
+ mdx: (Joi) => Joi.object({
56
+ loader: Joi.string(),
57
+ loaderOptions: Joi.object(),
58
+ }),
53
59
  mfsu: (Joi) => Joi.alternatives(Joi.object({
60
+ cacheDirectory: Joi.string(),
54
61
  esbuild: Joi.boolean(),
62
+ mfName: Joi.string(),
55
63
  }), Joi.boolean()),
56
64
  outputPath: (Joi) => Joi.string(),
57
65
  postcssLoader: (Joi) => Joi.object(),
58
66
  proxy: (Joi) => Joi.object(),
59
67
  publicPath: (Joi) => Joi.string(),
60
68
  purgeCSS: (Joi) => Joi.object(),
69
+ runtimePublicPath: (Joi) => Joi.object(),
61
70
  sassLoader: (Joi) => Joi.object(),
62
71
  srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
63
72
  styleLoader: (Joi) => Joi.object(),
64
- svgr: (Joi) => Joi.object(),
65
73
  svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
74
+ svgr: (Joi) => Joi.object(),
66
75
  targets: (Joi) => Joi.object(),
67
- writeToDisk: (Joi) => Joi.boolean(),
68
- esm: (Joi) => Joi.object(),
69
76
  theme: (Joi) => Joi.object(),
77
+ writeToDisk: (Joi) => Joi.boolean(),
70
78
  };
71
79
  }
72
80
  exports.getSchemas = getSchemas;
@@ -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
@@ -118,7 +137,10 @@ function createServer(opts) {
118
137
  });
119
138
  }
120
139
  // after middlewares
121
- (opts.afterMiddlewares || []).forEach((m) => app.use(m));
140
+ (opts.afterMiddlewares || []).forEach((m) => {
141
+ // TODO: FIXME
142
+ app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
143
+ });
122
144
  // history fallback
123
145
  app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
124
146
  index: '/',
@@ -150,7 +172,7 @@ function createServer(opts) {
150
172
  const port = opts.port || 8000;
151
173
  server.listen(port, () => {
152
174
  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}`);
175
+ utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`http://${host}:${port}`)}`);
154
176
  });
155
177
  return server;
156
178
  });
@@ -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;