@umijs/bundler-webpack 4.0.0-canary.20220429.3 → 4.0.0-canary.20220429.4

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 (97) hide show
  1. package/dist/build.d.ts +20 -0
  2. package/dist/build.js +75 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +90 -0
  5. package/dist/client/client.d.ts +1 -0
  6. package/dist/client/client.js +258 -0
  7. package/dist/config/_sampleFeature.d.ts +10 -0
  8. package/dist/config/_sampleFeature.js +22 -0
  9. package/dist/config/assetRules.d.ts +11 -0
  10. package/dist/config/assetRules.js +61 -0
  11. package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
  12. package/dist/config/bundleAnalyzerPlugin.js +30 -0
  13. package/dist/config/compressPlugin.d.ts +10 -0
  14. package/dist/config/compressPlugin.js +91 -0
  15. package/dist/config/config.d.ts +27 -0
  16. package/dist/config/config.js +226 -0
  17. package/dist/config/copyPlugin.d.ts +10 -0
  18. package/dist/config/copyPlugin.js +49 -0
  19. package/dist/config/cssRules.d.ts +11 -0
  20. package/dist/config/cssRules.js +98 -0
  21. package/dist/config/definePlugin.d.ts +15 -0
  22. package/dist/config/definePlugin.js +45 -0
  23. package/dist/config/detectDeadCode.d.ts +12 -0
  24. package/dist/config/detectDeadCode.js +120 -0
  25. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  26. package/dist/config/detectDeadCodePlugin.js +75 -0
  27. package/dist/config/fastRefreshPlugin.d.ts +12 -0
  28. package/dist/config/fastRefreshPlugin.js +34 -0
  29. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  30. package/dist/config/forkTSCheckerPlugin.js +34 -0
  31. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  32. package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
  33. package/dist/config/ignorePlugin.d.ts +10 -0
  34. package/dist/config/ignorePlugin.js +27 -0
  35. package/dist/config/javaScriptRules.d.ts +16 -0
  36. package/dist/config/javaScriptRules.js +188 -0
  37. package/dist/config/manifestPlugin.d.ts +11 -0
  38. package/dist/config/manifestPlugin.js +25 -0
  39. package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
  40. package/dist/config/miniCSSExtractPlugin.js +33 -0
  41. package/dist/config/nodePolyfill.d.ts +10 -0
  42. package/dist/config/nodePolyfill.js +35 -0
  43. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  44. package/dist/config/nodePrefixPlugin.js +25 -0
  45. package/dist/config/progressPlugin.d.ts +11 -0
  46. package/dist/config/progressPlugin.js +27 -0
  47. package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
  48. package/dist/config/purgecssWebpackPlugin.js +32 -0
  49. package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
  50. package/dist/config/speedMeasureWebpackPlugin.js +34 -0
  51. package/dist/config/svgRules.d.ts +12 -0
  52. package/dist/config/svgRules.js +57 -0
  53. package/dist/constants.d.ts +15 -0
  54. package/dist/constants.js +24 -0
  55. package/dist/dev.d.ts +25 -0
  56. package/dist/dev.js +145 -0
  57. package/dist/index.d.ts +8 -0
  58. package/dist/index.js +20 -0
  59. package/dist/loader/svgr.d.ts +4 -0
  60. package/dist/loader/svgr.js +67 -0
  61. package/dist/loader/swc.d.ts +4 -0
  62. package/dist/loader/swc.js +79 -0
  63. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +11 -0
  64. package/dist/plugins/ESBuildCSSMinifyPlugin.js +63 -0
  65. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  66. package/dist/plugins/ParcelCSSMinifyPlugin.js +75 -0
  67. package/dist/plugins/ProgressPlugin.d.ts +15 -0
  68. package/dist/plugins/ProgressPlugin.js +44 -0
  69. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  70. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  71. package/dist/plugins/_SamplePlugin.d.ts +9 -0
  72. package/dist/plugins/_SamplePlugin.js +14 -0
  73. package/dist/requireHook.d.ts +1 -0
  74. package/dist/requireHook.js +31 -0
  75. package/dist/schema.d.ts +3 -0
  76. package/dist/schema.js +84 -0
  77. package/dist/server/server.d.ts +17 -0
  78. package/dist/server/server.js +202 -0
  79. package/dist/server/ws.d.ts +11 -0
  80. package/dist/server/ws.js +42 -0
  81. package/dist/swcPlugins/autoCSSModules.d.ts +13 -0
  82. package/dist/swcPlugins/autoCSSModules.js +34 -0
  83. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  84. package/dist/swcPlugins/changeImportFromString.js +10 -0
  85. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  86. package/dist/swcPlugins/lockCoreJS.js +24 -0
  87. package/dist/types.d.ts +119 -0
  88. package/dist/types.js +30 -0
  89. package/dist/utils/browsersList.d.ts +5 -0
  90. package/dist/utils/browsersList.js +10 -0
  91. package/dist/utils/depMatch.d.ts +6 -0
  92. package/dist/utils/depMatch.js +46 -0
  93. package/dist/utils/formatWebpackMessages.d.ts +12 -0
  94. package/dist/utils/formatWebpackMessages.js +100 -0
  95. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  96. package/dist/utils/getEsBuildTarget.js +12 -0
  97. package/package.json +5 -5
@@ -0,0 +1,33 @@
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
+ exports.addMiniCSSExtractPlugin = void 0;
16
+ // @ts-ignore
17
+ const mini_css_extract_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/mini-css-extract-plugin"));
18
+ function addMiniCSSExtractPlugin(opts) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const { config, userConfig, useHash } = opts;
21
+ const hash = useHash ? '.[contenthash:8]' : '';
22
+ if (!userConfig.styleLoader) {
23
+ config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
24
+ {
25
+ filename: `[name]${hash}.css`,
26
+ chunkFilename: `[name]${hash}.chunk.css`,
27
+ ignoreOrder: true,
28
+ },
29
+ ]);
30
+ }
31
+ });
32
+ }
33
+ exports.addMiniCSSExtractPlugin = addMiniCSSExtractPlugin;
@@ -0,0 +1,10 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ }
9
+ export declare function addNodePolyfill(opts: IOpts): Promise<void>;
10
+ export {};
@@ -0,0 +1,35 @@
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.addNodePolyfill = void 0;
13
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
+ function addNodePolyfill(opts) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const { config } = opts;
17
+ const nodeLibs = require('node-libs-browser');
18
+ config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
19
+ {
20
+ Buffer: ['buffer', 'Buffer'],
21
+ process: nodeLibs['process'],
22
+ },
23
+ ]);
24
+ config.resolve.fallback.merge(Object.assign(Object.assign({}, Object.keys(nodeLibs).reduce((memo, key) => {
25
+ if (nodeLibs[key]) {
26
+ memo[key] = nodeLibs[key];
27
+ }
28
+ else {
29
+ memo[key] = false;
30
+ }
31
+ return memo;
32
+ }, {})), { http: false, https: false }));
33
+ });
34
+ }
35
+ exports.addNodePolyfill = addNodePolyfill;
@@ -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 addNodePrefixPlugin(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.addNodePrefixPlugin = void 0;
13
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
+ function addNodePrefixPlugin(opts) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const { config } = opts;
17
+ config.plugin('node-prefix-plugin').use(webpack_1.NormalModuleReplacementPlugin, [
18
+ /^node:/,
19
+ (resource) => {
20
+ resource.request = resource.request.replace(/^node:/, '');
21
+ },
22
+ ]);
23
+ });
24
+ }
25
+ exports.addNodePrefixPlugin = addNodePrefixPlugin;
@@ -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 addProgressPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,27 @@
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
+ exports.addProgressPlugin = void 0;
16
+ const ProgressPlugin_1 = __importDefault(require("../plugins/ProgressPlugin"));
17
+ function addProgressPlugin(opts) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const { config, name } = opts;
20
+ config.plugin('progress-plugin').use(ProgressPlugin_1.default, [
21
+ {
22
+ name,
23
+ },
24
+ ]);
25
+ });
26
+ }
27
+ exports.addProgressPlugin = addProgressPlugin;
@@ -0,0 +1,10 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ }
9
+ export declare function applyPurgeCSSWebpackPlugin(opts: IOpts): Promise<void>;
10
+ export {};
@@ -0,0 +1,32 @@
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.applyPurgeCSSWebpackPlugin = void 0;
13
+ const types_1 = require("../types");
14
+ function applyPurgeCSSWebpackPlugin(opts) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const { config, userConfig, cwd, env } = opts;
17
+ config;
18
+ userConfig;
19
+ cwd;
20
+ env;
21
+ if (userConfig.purgeCSS && env === types_1.Env.production) {
22
+ config
23
+ .plugin('purgecss-webpack-plugin')
24
+ .use(require('@umijs/bundler-webpack/compiled/purgecss-webpack-plugin'), [
25
+ {
26
+ paths: [],
27
+ },
28
+ ]);
29
+ }
30
+ });
31
+ }
32
+ exports.applyPurgeCSSWebpackPlugin = applyPurgeCSSWebpackPlugin;
@@ -0,0 +1,6 @@
1
+ import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
2
+ interface IOpts {
3
+ webpackConfig: Configuration;
4
+ }
5
+ export declare function addSpeedMeasureWebpackPlugin(opts: IOpts): Promise<Configuration>;
6
+ export {};
@@ -0,0 +1,34 @@
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
+ exports.addSpeedMeasureWebpackPlugin = void 0;
16
+ // @ts-ignore
17
+ const speed_measure_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/speed-measure-webpack-plugin"));
18
+ const path_1 = require("path");
19
+ function addSpeedMeasureWebpackPlugin(opts) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ let webpackConfig = opts.webpackConfig;
22
+ if (process.env.SPEED_MEASURE) {
23
+ const smpOption = process.env.SPEED_MEASURE === 'JSON'
24
+ ? {
25
+ outputFormat: 'json',
26
+ outputTarget: (0, path_1.join)(process.cwd(), 'SPEED_MEASURE.json'),
27
+ }
28
+ : { outputFormat: 'human', outputTarget: console.log };
29
+ webpackConfig = new speed_measure_webpack_plugin_1.default(smpOption).wrap(webpackConfig);
30
+ }
31
+ return webpackConfig;
32
+ });
33
+ }
34
+ exports.addSpeedMeasureWebpackPlugin = addSpeedMeasureWebpackPlugin;
@@ -0,0 +1,12 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ browsers: any;
9
+ staticPathPrefix: string;
10
+ }
11
+ export declare function addSVGRules(opts: IOpts): Promise<void>;
12
+ export {};
@@ -0,0 +1,57 @@
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.addSVGRules = void 0;
13
+ function addSVGRules(opts) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const { config, userConfig } = opts;
16
+ const { svgr, svgo = {} } = userConfig;
17
+ if (svgr) {
18
+ const svgrRule = config.module.rule('svgr');
19
+ svgrRule
20
+ .test(/\.svg$/)
21
+ .issuer(/\.[jt]sx?$/)
22
+ .type('javascript/auto')
23
+ .use('svgr-loader')
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();
39
+ }
40
+ if (svgo === false) {
41
+ const svgRule = config.module.rule('svg');
42
+ svgRule
43
+ .test(/\.svg$/)
44
+ .use('url-loader')
45
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'));
46
+ return;
47
+ }
48
+ const svgRule = config.module.rule('svg');
49
+ svgRule
50
+ .test(/\.svg$/)
51
+ .use('svgo-loader')
52
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
53
+ .options(Object.assign({ configFile: false }, svgo))
54
+ .end();
55
+ });
56
+ }
57
+ exports.addSVGRules = addSVGRules;
@@ -0,0 +1,15 @@
1
+ export declare const DEFAULT_DEVTOOL = "cheap-module-source-map";
2
+ export declare const DEFAULT_OUTPUT_PATH = "dist";
3
+ export declare const MFSU_NAME = "MFSU";
4
+ export declare enum MESSAGE_TYPE {
5
+ ok = "ok",
6
+ warnings = "warnings",
7
+ errors = "errors",
8
+ hash = "hash",
9
+ stillOk = "still-ok",
10
+ invalid = "invalid"
11
+ }
12
+ export declare const DEFAULT_BROWSER_TARGETS: {
13
+ chrome: number;
14
+ };
15
+ export declare const DEFAULT_ESBUILD_TARGET_KEYS: string[];
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
4
+ exports.DEFAULT_DEVTOOL = 'cheap-module-source-map';
5
+ exports.DEFAULT_OUTPUT_PATH = 'dist';
6
+ exports.MFSU_NAME = 'MFSU';
7
+ var MESSAGE_TYPE;
8
+ (function (MESSAGE_TYPE) {
9
+ MESSAGE_TYPE["ok"] = "ok";
10
+ MESSAGE_TYPE["warnings"] = "warnings";
11
+ MESSAGE_TYPE["errors"] = "errors";
12
+ MESSAGE_TYPE["hash"] = "hash";
13
+ MESSAGE_TYPE["stillOk"] = "still-ok";
14
+ MESSAGE_TYPE["invalid"] = "invalid";
15
+ })(MESSAGE_TYPE = exports.MESSAGE_TYPE || (exports.MESSAGE_TYPE = {}));
16
+ exports.DEFAULT_BROWSER_TARGETS = {
17
+ chrome: 80,
18
+ };
19
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = [
20
+ 'chrome',
21
+ 'firefox',
22
+ 'edge',
23
+ 'safari',
24
+ ];
package/dist/dev.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { IOpts as IConfigOpts } from './config/config';
2
+ import { IConfig } from './types';
3
+ declare type IOpts = {
4
+ afterMiddlewares?: any[];
5
+ beforeMiddlewares?: any[];
6
+ onDevCompileDone?: Function;
7
+ onProgress?: Function;
8
+ onMFSUProgress?: Function;
9
+ port?: number;
10
+ host?: string;
11
+ babelPreset?: any;
12
+ chainWebpack?: Function;
13
+ modifyWebpackConfig?: Function;
14
+ beforeBabelPlugins?: any[];
15
+ beforeBabelPresets?: any[];
16
+ extraBabelPlugins?: any[];
17
+ extraBabelPresets?: any[];
18
+ cwd: string;
19
+ rootDir?: string;
20
+ config: IConfig;
21
+ entry: Record<string, string>;
22
+ } & Pick<IConfigOpts, 'cache'>;
23
+ export declare function stripUndefined(obj: any): any;
24
+ export declare function dev(opts: IOpts): Promise<void>;
25
+ export {};
package/dist/dev.js ADDED
@@ -0,0 +1,145 @@
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
+ exports.dev = exports.stripUndefined = void 0;
16
+ const mfsu_1 = require("@umijs/mfsu");
17
+ const utils_1 = require("@umijs/utils");
18
+ const fs_1 = require("fs");
19
+ const path_1 = require("path");
20
+ const webpack_1 = __importDefault(require("../compiled/webpack"));
21
+ const config_1 = require("./config/config");
22
+ const constants_1 = require("./constants");
23
+ const server_1 = require("./server/server");
24
+ const types_1 = require("./types");
25
+ function stripUndefined(obj) {
26
+ Object.keys(obj).forEach((key) => {
27
+ if (obj[key] === undefined) {
28
+ delete obj[key];
29
+ }
30
+ });
31
+ return obj;
32
+ }
33
+ exports.stripUndefined = stripUndefined;
34
+ function dev(opts) {
35
+ var _a, _b, _c, _d, _e, _f;
36
+ var _g;
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const enableMFSU = opts.config.mfsu !== false;
39
+ let mfsu = null;
40
+ if (enableMFSU) {
41
+ if (opts.config.srcTranspiler === types_1.Transpiler.swc) {
42
+ utils_1.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
43
+ }
44
+ mfsu = new mfsu_1.MFSU({
45
+ implementor: webpack_1.default,
46
+ buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
47
+ depBuildConfig: {
48
+ extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
49
+ },
50
+ mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
51
+ runtimePublicPath: opts.config.runtimePublicPath,
52
+ tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
53
+ (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules/.cache/mfsu'),
54
+ onMFSUProgress: opts.onMFSUProgress,
55
+ getCacheDependency() {
56
+ return stripUndefined({
57
+ version: require('../package.json').version,
58
+ mfsu: opts.config.mfsu,
59
+ alias: opts.config.alias,
60
+ externals: opts.config.externals,
61
+ theme: opts.config.theme,
62
+ runtimePublicPath: opts.config.runtimePublicPath,
63
+ publicPath: opts.config.publicPath,
64
+ });
65
+ },
66
+ });
67
+ }
68
+ const webpackConfig = yield (0, config_1.getConfig)({
69
+ cwd: opts.cwd,
70
+ rootDir: opts.rootDir,
71
+ env: types_1.Env.development,
72
+ entry: opts.entry,
73
+ userConfig: opts.config,
74
+ babelPreset: opts.babelPreset,
75
+ extraBabelPlugins: [
76
+ ...(opts.beforeBabelPlugins || []),
77
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
78
+ ...(opts.extraBabelPlugins || []),
79
+ ],
80
+ extraBabelPresets: [
81
+ ...(opts.beforeBabelPresets || []),
82
+ ...(opts.extraBabelPresets || []),
83
+ ],
84
+ extraBabelIncludes: opts.config.extraBabelIncludes,
85
+ extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
86
+ chainWebpack: opts.chainWebpack,
87
+ modifyWebpackConfig: opts.modifyWebpackConfig,
88
+ hmr: true,
89
+ analyze: process.env.ANALYZE,
90
+ cache: opts.cache,
91
+ });
92
+ const depConfig = yield (0, config_1.getConfig)({
93
+ cwd: opts.cwd,
94
+ rootDir: opts.rootDir,
95
+ env: types_1.Env.development,
96
+ entry: opts.entry,
97
+ userConfig: opts.config,
98
+ hash: true,
99
+ staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
100
+ name: constants_1.MFSU_NAME,
101
+ chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
102
+ cache: {
103
+ buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
104
+ cacheDirectory: (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
105
+ },
106
+ });
107
+ (_g = webpackConfig.resolve).alias || (_g.alias = {});
108
+ // TODO: REMOVE ME
109
+ ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
110
+ // @ts-ignore
111
+ webpackConfig.resolve.alias[dep] = require.resolve(dep);
112
+ });
113
+ yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
114
+ config: webpackConfig,
115
+ depConfig: depConfig,
116
+ }));
117
+ if (mfsu &&
118
+ webpackConfig.cache &&
119
+ typeof webpackConfig.cache === 'object' &&
120
+ webpackConfig.cache.type === 'filesystem') {
121
+ const webpackCachePath = (0, path_1.join)(webpackConfig.cache.cacheDirectory, `default-development`, 'index.pack');
122
+ const mfsuCacheExists = (0, fs_1.existsSync)(mfsu.depInfo.cacheFilePath);
123
+ const webpackCacheExists = (0, fs_1.existsSync)(webpackCachePath);
124
+ if (webpackCacheExists && !mfsuCacheExists) {
125
+ utils_1.logger.warn(`Invalidate webpack cache since mfsu cache is missing`);
126
+ utils_1.rimraf.sync(webpackConfig.cache.cacheDirectory);
127
+ }
128
+ }
129
+ yield (0, server_1.createServer)({
130
+ webpackConfig,
131
+ userConfig: opts.config,
132
+ cwd: opts.cwd,
133
+ beforeMiddlewares: [
134
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getMiddlewares()) || []),
135
+ ...(opts.beforeMiddlewares || []),
136
+ ],
137
+ port: opts.port,
138
+ host: opts.host,
139
+ afterMiddlewares: [...(opts.afterMiddlewares || [])],
140
+ onDevCompileDone: opts.onDevCompileDone,
141
+ onProgress: opts.onProgress,
142
+ });
143
+ });
144
+ }
145
+ exports.dev = dev;
@@ -0,0 +1,8 @@
1
+ import type webpack from '../compiled/webpack';
2
+ export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
3
+ export type { Compiler, Stats } from '../compiled/webpack';
4
+ export * from './build';
5
+ export * from './config/config';
6
+ export * from './dev';
7
+ export * from './schema';
8
+ export { webpack };
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./build"), exports);
18
+ __exportStar(require("./config/config"), exports);
19
+ __exportStar(require("./dev"), exports);
20
+ __exportStar(require("./schema"), exports);
@@ -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;