@umijs/bundler-webpack 4.0.0-beta.9 → 4.0.0-rc.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 (101) hide show
  1. package/compiled/autoprefixer/browserslist/index.d.ts +7 -7
  2. package/compiled/autoprefixer/index.js +3 -3
  3. package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
  4. package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
  5. package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
  6. package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
  7. package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
  8. package/compiled/autoprefixer/postcss/lib/node.d.ts +36 -2
  9. package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
  10. package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
  11. package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
  12. package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
  13. package/compiled/babel-loader/index.js +2 -2
  14. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  15. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  16. package/compiled/fork-ts-checker-webpack-plugin/index.js +49 -0
  17. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  18. package/compiled/mini-css-extract-plugin/index.js +6769 -6731
  19. package/compiled/mini-css-extract-plugin/loader.js +1 -1
  20. package/compiled/mini-css-extract-plugin/utils.js +11 -6
  21. package/compiled/postcss-loader/index.js +1 -1
  22. package/compiled/react-refresh/index.js +3 -3
  23. package/compiled/sass-loader/index.js +1 -1
  24. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  25. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  26. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  27. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  28. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  29. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  30. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  31. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  32. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  33. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  34. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  35. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  36. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  37. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  38. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  39. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  40. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  41. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  42. package/compiled/schema-utils/index.js +8 -2
  43. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  44. package/compiled/style-loader/index.js +1 -1
  45. package/compiled/terser/index.js +1 -1
  46. package/compiled/terser-webpack-plugin/index.js +328 -451
  47. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  48. package/compiled/terser-webpack-plugin/minify.js +6 -1
  49. package/compiled/terser-webpack-plugin/types/index.d.ts +3 -3
  50. package/compiled/terser-webpack-plugin/types/utils.d.ts +9 -12
  51. package/compiled/terser-webpack-plugin/utils.js +113 -17
  52. package/compiled/webpack/index.js +4915 -4485
  53. package/compiled/webpack-dev-middleware/index.js +11 -5
  54. package/compiled/webpack-manifest-plugin/LICENSE +21 -0
  55. package/compiled/webpack-manifest-plugin/index.js +1 -0
  56. package/compiled/webpack-manifest-plugin/package.json +1 -0
  57. package/compiled/webpack-sources/index.js +1 -1
  58. package/dist/build.d.ts +3 -2
  59. package/dist/build.js +1 -0
  60. package/dist/cli.js +4 -7
  61. package/dist/config/assetRules.js +6 -14
  62. package/dist/config/config.d.ts +7 -2
  63. package/dist/config/config.js +45 -4
  64. package/dist/config/cssRules.js +1 -1
  65. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  66. package/dist/config/forkTSCheckerPlugin.js +34 -0
  67. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  68. package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
  69. package/dist/config/javaScriptRules.d.ts +1 -0
  70. package/dist/config/javaScriptRules.js +33 -19
  71. package/dist/config/manifestPlugin.d.ts +11 -0
  72. package/dist/config/manifestPlugin.js +25 -0
  73. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  74. package/dist/config/miniCSSExtractPlugin.js +2 -3
  75. package/dist/config/svgRules.d.ts +1 -0
  76. package/dist/config/svgRules.js +17 -3
  77. package/dist/dev.d.ts +3 -2
  78. package/dist/dev.js +29 -5
  79. package/dist/esbuildHandler/autoCssModules.d.ts +2 -0
  80. package/dist/esbuildHandler/autoCssModules.js +23 -0
  81. package/dist/loader/esbuild.d.ts +5 -0
  82. package/dist/loader/esbuild.js +53 -0
  83. package/dist/loader/svgr.d.ts +4 -0
  84. package/dist/loader/svgr.js +67 -0
  85. package/dist/loader/swc.d.ts +4 -0
  86. package/dist/loader/swc.js +83 -0
  87. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  88. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  89. package/dist/schema.js +11 -5
  90. package/dist/server/server.js +20 -1
  91. package/dist/swcPlugins/autoCSSModules.js +6 -4
  92. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  93. package/dist/swcPlugins/lockCoreJS.js +23 -0
  94. package/dist/types.d.ts +18 -0
  95. package/package.json +36 -31
  96. package/compiled/@svgr/webpack/LICENSE +0 -7
  97. package/compiled/@svgr/webpack/index.js +0 -266
  98. package/compiled/@svgr/webpack/package.json +0 -1
  99. package/compiled/swc-loader/LICENSE +0 -25
  100. package/compiled/swc-loader/index.js +0 -1
  101. package/compiled/swc-loader/package.json +0 -1
@@ -14,13 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.addJavaScriptRules = void 0;
16
16
  const utils_1 = require("@umijs/utils");
17
+ const webpack_1 = require("../../compiled/webpack");
17
18
  const constants_1 = require("../constants");
19
+ const autoCssModules_1 = __importDefault(require("../esbuildHandler/autoCssModules"));
20
+ const esbuild_1 = require("../loader/esbuild");
18
21
  const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
19
22
  const types_1 = require("../types");
20
23
  const depMatch_1 = require("../utils/depMatch");
21
24
  function addJavaScriptRules(opts) {
25
+ var _a, _b;
22
26
  return __awaiter(this, void 0, void 0, function* () {
23
- const { config, userConfig, cwd, env, name } = opts;
27
+ const { config, userConfig, cwd, name } = opts;
24
28
  const isDev = opts.env === types_1.Env.development;
25
29
  const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
26
30
  const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
@@ -54,6 +58,9 @@ function addJavaScriptRules(opts) {
54
58
  })
55
59
  .end(),
56
60
  ];
61
+ if (userConfig.mdx) {
62
+ srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
63
+ }
57
64
  const depRules = [
58
65
  config.module
59
66
  .rule('dep')
@@ -115,32 +122,39 @@ function addJavaScriptRules(opts) {
115
122
  // TODO: support javascript
116
123
  rule
117
124
  .use('swc-loader')
118
- .loader(require.resolve('../../compiled/swc-loader'))
125
+ .loader(require.resolve('../loader/swc'))
119
126
  .options({
120
- jsc: {
121
- parser: {
122
- syntax: 'typescript',
123
- dynamicImport: true,
124
- tsx: true,
125
- },
126
- transform: {
127
- react: {
128
- runtime: 'automatic',
129
- pragma: 'React.createElement',
130
- pragmaFrag: 'React.Fragment',
131
- throwIfNamespace: true,
132
- development: env === types_1.Env.development,
133
- useBuiltins: true,
134
- },
135
- },
136
- },
137
127
  plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
128
+ targets: userConfig.targets,
138
129
  });
139
130
  }
131
+ else if (srcTranspiler === types_1.Transpiler.esbuild) {
132
+ rule
133
+ .use('esbuild-loader')
134
+ .loader(esbuild_1.esbuildLoaderPath)
135
+ .options({
136
+ target: isDev ? 'esnext' : 'es2015',
137
+ handler: [autoCssModules_1.default, ...opts.extraEsbuildLoaderHandler],
138
+ });
139
+ // esbuild loader can not auto import `React`
140
+ config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
141
+ {
142
+ React: 'react',
143
+ },
144
+ ]);
145
+ }
140
146
  else {
141
147
  throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
142
148
  }
143
149
  });
150
+ if (userConfig.mdx) {
151
+ config.module
152
+ .rule('mdx')
153
+ .test(/\.mdx?$/)
154
+ .use('mdx-loader')
155
+ .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
156
+ .options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
157
+ }
144
158
  const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
145
159
  depRules.forEach((_rule) => {
146
160
  if (depTranspiler === types_1.Transpiler.none) {
@@ -0,0 +1,11 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ name?: string;
5
+ config: Config;
6
+ userConfig: IConfig;
7
+ cwd: string;
8
+ env: Env;
9
+ }
10
+ export declare function addManifestPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,25 @@
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.addManifestPlugin = void 0;
13
+ // @ts-ignore
14
+ const webpack_manifest_plugin_1 = require("@umijs/bundler-webpack/compiled/webpack-manifest-plugin");
15
+ function addManifestPlugin(opts) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const { config, userConfig } = opts;
18
+ if (userConfig.manifest) {
19
+ config.plugin('manifest-plugin').use(webpack_manifest_plugin_1.WebpackManifestPlugin, [
20
+ Object.assign({ fileName: 'asset-manifest.json' }, userConfig.manifest),
21
+ ]);
22
+ }
23
+ });
24
+ }
25
+ exports.addManifestPlugin = addManifestPlugin;
@@ -5,6 +5,7 @@ interface IOpts {
5
5
  userConfig: IConfig;
6
6
  cwd: string;
7
7
  env: Env;
8
+ useHash: boolean;
8
9
  }
9
10
  export declare function addMiniCSSExtractPlugin(opts: IOpts): Promise<void>;
10
11
  export {};
@@ -15,11 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.addMiniCSSExtractPlugin = void 0;
16
16
  // @ts-ignore
17
17
  const mini_css_extract_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/mini-css-extract-plugin"));
18
- const types_1 = require("../types");
19
18
  function addMiniCSSExtractPlugin(opts) {
20
19
  return __awaiter(this, void 0, void 0, function* () {
21
- const { config, userConfig, env } = opts;
22
- const hash = env !== types_1.Env.development && userConfig.hash ? '.[contenthash:8]' : '';
20
+ const { config, userConfig, useHash } = opts;
21
+ const hash = useHash ? '.[contenthash:8]' : '';
23
22
  if (!userConfig.styleLoader) {
24
23
  config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
25
24
  {
@@ -6,6 +6,7 @@ interface IOpts {
6
6
  cwd: string;
7
7
  env: Env;
8
8
  browsers: any;
9
+ staticPathPrefix: string;
9
10
  }
10
11
  export declare function addSVGRules(opts: IOpts): Promise<void>;
11
12
  export {};
@@ -17,11 +17,25 @@ function addSVGRules(opts) {
17
17
  if (svgr) {
18
18
  const svgrRule = config.module.rule('svgr');
19
19
  svgrRule
20
- .test(/\.svg$/i)
20
+ .test(/\.svg$/)
21
21
  .issuer(/\.[jt]sx?$/)
22
+ .type('javascript/auto')
22
23
  .use('svgr-loader')
23
- .loader(require.resolve('@umijs/bundler-webpack/compiled/@svgr/webpack'))
24
- .options(Object.assign(Object.assign({ svgoConfig: Object.assign({}, (svgo || {})) }, svgr), { svgo: !!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 }))
35
+ .end()
36
+ .use('url-loader')
37
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
38
+ .end();
25
39
  }
26
40
  if (svgo === false) {
27
41
  const svgRule = config.module.rule('svg');
package/dist/dev.d.ts CHANGED
@@ -1,5 +1,6 @@
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;
@@ -14,6 +15,6 @@ interface IOpts {
14
15
  cwd: string;
15
16
  config: IConfig;
16
17
  entry: Record<string, string>;
17
- }
18
+ } & Pick<IConfigOpts, 'cache'>;
18
19
  export declare function dev(opts: IOpts): Promise<void>;
19
20
  export {};
package/dist/dev.js CHANGED
@@ -14,21 +14,39 @@ 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;
26
+ var _e;
25
27
  return __awaiter(this, void 0, void 0, function* () {
26
28
  const enableMFSU = opts.config.mfsu !== false;
27
29
  let mfsu = null;
28
30
  if (enableMFSU) {
31
+ if (opts.config.srcTranspiler === types_1.Transpiler.swc) {
32
+ utils_1.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
33
+ }
29
34
  mfsu = new mfsu_1.MFSU({
30
35
  implementor: webpack_1.default,
31
36
  buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
37
+ depBuildConfig: {
38
+ extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
39
+ },
40
+ mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
41
+ runtimePublicPath: opts.config.runtimePublicPath,
42
+ tmpBase: (0, path_1.join)(opts.cwd, 'node_modules/.cache/mfsu'),
43
+ getCacheDependency() {
44
+ var _a;
45
+ return {
46
+ version: require('../package.json').version,
47
+ esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
48
+ };
49
+ },
32
50
  });
33
51
  }
34
52
  const webpackConfig = yield (0, config_1.getConfig)({
@@ -45,10 +63,12 @@ function dev(opts) {
45
63
  ...(opts.beforeBabelPresets || []),
46
64
  ...(opts.extraBabelPresets || []),
47
65
  ],
66
+ extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
48
67
  chainWebpack: opts.chainWebpack,
49
68
  modifyWebpackConfig: opts.modifyWebpackConfig,
50
69
  hmr: true,
51
70
  analyze: process.env.ANALYZE,
71
+ cache: opts.cache,
52
72
  });
53
73
  const depConfig = yield (0, config_1.getConfig)({
54
74
  cwd: opts.cwd,
@@ -58,17 +78,21 @@ function dev(opts) {
58
78
  hash: true,
59
79
  staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
60
80
  name: constants_1.MFSU_NAME,
81
+ cache: {
82
+ buildDependencies: (_d = opts.cache) === null || _d === void 0 ? void 0 : _d.buildDependencies,
83
+ cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
84
+ },
61
85
  });
62
- (_b = webpackConfig.resolve).alias || (_b.alias = {});
86
+ (_e = webpackConfig.resolve).alias || (_e.alias = {});
63
87
  // TODO: REMOVE ME
64
88
  ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
65
89
  // @ts-ignore
66
90
  webpackConfig.resolve.alias[dep] = require.resolve(dep);
67
91
  });
68
- mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
92
+ yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
69
93
  config: webpackConfig,
70
94
  depConfig: depConfig,
71
- });
95
+ }));
72
96
  yield (0, server_1.createServer)({
73
97
  webpackConfig,
74
98
  userConfig: opts.config,
@@ -0,0 +1,2 @@
1
+ import { IEsbuildLoaderHandlerParams } from '../types';
2
+ export default function autoCssModulesHandler(opts: IEsbuildLoaderHandlerParams): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@umijs/utils");
4
+ const CSS_MODULES_QUERY = '?modules';
5
+ const QUERY_LENGTH = CSS_MODULES_QUERY.length;
6
+ function autoCssModulesHandler(opts) {
7
+ let { code } = opts;
8
+ let offset = 0;
9
+ opts.imports.forEach((i) => {
10
+ if (i.d < 0 && (0, utils_1.isStyleFile)({ filename: i.n })) {
11
+ // import x from './index.less'
12
+ // => import x from '
13
+ const importSegment = code.substring(i.ss + offset, i.s + offset);
14
+ // is css module
15
+ if (~importSegment.indexOf(' from')) {
16
+ code = `${code.substring(0, i.e + offset)}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
17
+ offset += QUERY_LENGTH;
18
+ }
19
+ }
20
+ });
21
+ return code;
22
+ }
23
+ exports.default = autoCssModulesHandler;
@@ -0,0 +1,5 @@
1
+ import type { LoaderContext } from '../../compiled/webpack';
2
+ import type { IEsbuildLoaderOpts } from '../types';
3
+ declare function esbuildLoader(this: LoaderContext<IEsbuildLoaderOpts>, source: string): Promise<void>;
4
+ export default esbuildLoader;
5
+ export declare const esbuildLoaderPath: string;
@@ -0,0 +1,53 @@
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 __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.esbuildLoaderPath = void 0;
24
+ const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
25
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
26
+ const path_1 = require("path");
27
+ function esbuildLoader(source) {
28
+ var _a;
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const done = this.async();
31
+ const options = this.getOptions();
32
+ const { handler = [] } = options, otherOptions = __rest(options, ["handler"]);
33
+ const filePath = this.resourcePath;
34
+ const ext = (0, path_1.extname)(filePath).slice(1);
35
+ const transformOptions = Object.assign(Object.assign({}, otherOptions), { target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015', loader: ext !== null && ext !== void 0 ? ext : 'js', sourcemap: this.sourceMap, sourcefile: filePath });
36
+ try {
37
+ let { code, map } = yield (0, esbuild_1.transform)(source, transformOptions);
38
+ if (handler.length) {
39
+ yield es_module_lexer_1.init;
40
+ handler.forEach((handle) => {
41
+ const [imports, exports] = (0, es_module_lexer_1.parse)(code);
42
+ code = handle({ code, imports, exports, filePath });
43
+ });
44
+ }
45
+ done(null, code, map && JSON.parse(map));
46
+ }
47
+ catch (error) {
48
+ done(error);
49
+ }
50
+ });
51
+ }
52
+ exports.default = esbuildLoader;
53
+ exports.esbuildLoaderPath = __filename;
@@ -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,83 @@
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, targets = { chrome: '61' }, }) {
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
+ const polyfillOpts = isDev
21
+ ? {}
22
+ : {
23
+ env: {
24
+ /**
25
+ * need `@umijs/preset-umi/src/features/polyfill/swcPolyfill` config alias and provide polyfill
26
+ */
27
+ mode: 'usage',
28
+ coreJs: 3,
29
+ targets,
30
+ },
31
+ };
32
+ const swcOpts = Object.assign(Object.assign({ module: {
33
+ // @ts-ignore
34
+ type: 'es6',
35
+ ignoreDynamic: true,
36
+ } }, polyfillOpts), { jsc: {
37
+ parser: {
38
+ syntax: isTypeScript ? 'typescript' : 'ecmascript',
39
+ [isTypeScript ? 'tsx' : 'jsx']: !isTSFile,
40
+ dynamicImport: isTypeScript,
41
+ },
42
+ target: 'es2015',
43
+ transform: {
44
+ react: {
45
+ runtime: 'automatic',
46
+ pragma: 'React.createElement',
47
+ pragmaFrag: 'React.Fragment',
48
+ throwIfNamespace: true,
49
+ development: isDev,
50
+ useBuiltins: true,
51
+ },
52
+ },
53
+ } });
54
+ return swcOpts;
55
+ }
56
+ function swcLoader(contents) {
57
+ // 启用异步模式
58
+ const callback = this.async();
59
+ const loaderOpts = this.getOptions();
60
+ const { sync = false, parseMap = false, targets } = loaderOpts, otherOpts = __rest(loaderOpts, ["sync", "parseMap", "targets"]);
61
+ const filename = this.resourcePath;
62
+ const swcOpts = Object.assign(Object.assign(Object.assign({}, getBaseOpts({
63
+ filename,
64
+ targets,
65
+ })), { filename, sourceMaps: this.sourceMap, sourceFileName: filename }), otherOpts);
66
+ try {
67
+ if (sync) {
68
+ const output = (0, core_1.transformSync)(contents, swcOpts);
69
+ callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
70
+ }
71
+ else {
72
+ (0, core_1.transform)(contents, swcOpts).then((output) => {
73
+ callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
74
+ }, (err) => {
75
+ callback(err);
76
+ });
77
+ }
78
+ }
79
+ catch (e) {
80
+ callback(e);
81
+ }
82
+ }
83
+ 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;
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(),
@@ -36,28 +37,33 @@ function getSchemas() {
36
37
  define: (Joi) => Joi.object(),
37
38
  depTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
38
39
  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()),
40
+ externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
44
41
  extraBabelPlugins: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
45
42
  extraBabelPresets: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
46
43
  extraPostCSSPlugins: (Joi) => Joi.array(),
47
44
  fastRefresh: (Joi) => Joi.boolean(),
45
+ forkTSChecker: (Joi) => Joi.object(),
48
46
  hash: (Joi) => Joi.boolean(),
49
47
  ignoreMomentLocale: (Joi) => Joi.boolean(),
48
+ inlineLimit: (Joi) => Joi.number(),
50
49
  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
50
  jsMinifierOptions: (Joi) => Joi.object(),
52
51
  lessLoader: (Joi) => Joi.object(),
52
+ manifest: (Joi) => Joi.object(),
53
+ mdx: (Joi) => Joi.object({
54
+ loader: Joi.string(),
55
+ loaderOptions: Joi.object(),
56
+ }),
53
57
  mfsu: (Joi) => Joi.alternatives(Joi.object({
54
58
  esbuild: Joi.boolean(),
59
+ mfName: Joi.string(),
55
60
  }), Joi.boolean()),
56
61
  outputPath: (Joi) => Joi.string(),
57
62
  postcssLoader: (Joi) => Joi.object(),
58
63
  proxy: (Joi) => Joi.object(),
59
64
  publicPath: (Joi) => Joi.string(),
60
65
  purgeCSS: (Joi) => Joi.object(),
66
+ runtimePublicPath: (Joi) => Joi.object(),
61
67
  sassLoader: (Joi) => Joi.object(),
62
68
  srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
63
69
  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
  });