@umijs/bundler-vite 4.0.5 → 4.0.8

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 (49) hide show
  1. package/dist/build.d.ts +0 -0
  2. package/dist/build.js +118 -94
  3. package/dist/cli.d.ts +0 -0
  4. package/dist/cli.js +72 -64
  5. package/dist/config/config.d.ts +0 -0
  6. package/dist/config/config.js +70 -30
  7. package/dist/config/transformer/alias.d.ts +1 -1
  8. package/dist/config/transformer/alias.js +59 -47
  9. package/dist/config/transformer/css.d.ts +1 -1
  10. package/dist/config/transformer/css.js +71 -50
  11. package/dist/config/transformer/define.d.ts +1 -1
  12. package/dist/config/transformer/define.js +34 -14
  13. package/dist/config/transformer/index.d.ts +1 -1
  14. package/dist/config/transformer/index.js +51 -30
  15. package/dist/config/transformer/merge.d.ts +1 -1
  16. package/dist/config/transformer/merge.js +30 -9
  17. package/dist/config/transformer/optimizeDeps.d.ts +1 -1
  18. package/dist/config/transformer/optimizeDeps.js +34 -15
  19. package/dist/config/transformer/react.d.ts +1 -1
  20. package/dist/config/transformer/react.js +56 -28
  21. package/dist/config/transformer/rename.d.ts +1 -1
  22. package/dist/config/transformer/rename.js +53 -40
  23. package/dist/config/transformer/rollup.d.ts +1 -1
  24. package/dist/config/transformer/rollup.js +69 -62
  25. package/dist/config/transformer/target.d.ts +1 -1
  26. package/dist/config/transformer/target.js +58 -68
  27. package/dist/dev.d.ts +0 -0
  28. package/dist/dev.js +55 -31
  29. package/dist/index.d.ts +0 -0
  30. package/dist/index.js +19 -17
  31. package/dist/plugins/autoCSSModule.d.ts +0 -0
  32. package/dist/plugins/autoCSSModule.js +42 -37
  33. package/dist/plugins/deleteOutputFiles.d.ts +0 -0
  34. package/dist/plugins/deleteOutputFiles.js +37 -18
  35. package/dist/plugins/externals.d.ts +0 -0
  36. package/dist/plugins/externals.js +40 -21
  37. package/dist/plugins/index.d.ts +1 -1
  38. package/dist/plugins/index.js +39 -20
  39. package/dist/plugins/svgr.d.ts +0 -0
  40. package/dist/plugins/svgr.js +75 -48
  41. package/dist/schema.d.ts +0 -0
  42. package/dist/schema.js +67 -44
  43. package/dist/server/plugins/onHotUpdate.d.ts +0 -0
  44. package/dist/server/plugins/onHotUpdate.js +33 -10
  45. package/dist/server/server.d.ts +0 -1
  46. package/dist/server/server.js +110 -88
  47. package/dist/types.d.ts +0 -0
  48. package/dist/types.js +41 -14
  49. package/package.json +5 -5
package/dist/build.d.ts CHANGED
File without changes
package/dist/build.js CHANGED
@@ -1,102 +1,126 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
4
35
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.build = void 0;
7
- const utils_1 = require("@umijs/utils");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const vite_1 = require("../compiled/vite");
11
- const config_1 = require("./config/config");
12
- const deleteOutputFiles_1 = __importDefault(require("./plugins/deleteOutputFiles"));
13
- const types_1 = require("./types");
14
- /**
15
- * get umi template directory from entry
16
- */
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // build.ts
40
+ var build_exports = {};
41
+ __export(build_exports, {
42
+ build: () => build
43
+ });
44
+ module.exports = __toCommonJS(build_exports);
45
+ var import_utils = require("@umijs/utils");
46
+ var import_fs = __toESM(require("fs"));
47
+ var import_path = __toESM(require("path"));
48
+ var import_vite = require("../compiled/vite");
49
+ var import_config = require("./config/config");
50
+ var import_deleteOutputFiles = __toESM(require("./plugins/deleteOutputFiles"));
51
+ var import_types = require("./types");
17
52
  function getUmiTmpDir(entry) {
18
- const mainEntry = Object.values(entry).find((p) => p.includes('/umi.ts'));
19
- return mainEntry && path_1.default.dirname(mainEntry);
53
+ const mainEntry = Object.values(entry).find((p) => p.includes("/umi.ts"));
54
+ return mainEntry && import_path.default.dirname(mainEntry);
20
55
  }
21
- /**
22
- * generate temp html entry for vite builder
23
- * @param cwd project root
24
- * @param entry umi entry config
25
- */
26
56
  function generateTempEntry(cwd, entry) {
27
- const umiTmpDir = entry && getUmiTmpDir(entry);
28
- if (umiTmpDir) {
29
- const entryTmpDir = path_1.default.join(umiTmpDir, '.bundler-vite-entry');
30
- fs_1.default.mkdirSync(entryTmpDir);
31
- return Object.keys(entry).reduce((r, name) => {
32
- const entryFilePath = path_1.default.join(entryTmpDir, `${name}.html`);
33
- fs_1.default.writeFileSync(entryFilePath, `<html><head></head><body><script type="module" src="${entry[name]}"></script></body></html>`, 'utf8');
34
- return {
35
- ...r,
36
- [name]: path_1.default.relative(cwd, entryFilePath),
37
- };
38
- }, {});
39
- }
57
+ const umiTmpDir = entry && getUmiTmpDir(entry);
58
+ if (umiTmpDir) {
59
+ const entryTmpDir = import_path.default.join(umiTmpDir, ".bundler-vite-entry");
60
+ import_fs.default.mkdirSync(entryTmpDir);
61
+ return Object.keys(entry).reduce((r, name) => {
62
+ const entryFilePath = import_path.default.join(entryTmpDir, `${name}.html`);
63
+ import_fs.default.writeFileSync(entryFilePath, `<html><head></head><body><script type="module" src="${entry[name]}"><\/script></body></html>`, "utf8");
64
+ return __spreadProps(__spreadValues({}, r), {
65
+ [name]: import_path.default.relative(cwd, entryFilePath)
66
+ });
67
+ }, {});
68
+ }
40
69
  }
41
70
  async function build(opts) {
42
- let extraHtmlPart;
43
- const startTms = +new Date();
44
- const result = {
45
- isFirstCompile: true,
46
- time: 0,
47
- };
48
- const tmpHtmlEntry = generateTempEntry(opts.cwd, opts.entry);
49
- const viteUserConfig = await (0, config_1.getConfig)({
50
- cwd: opts.cwd,
51
- env: types_1.Env.production,
52
- entry: opts.entry,
53
- userConfig: opts.config,
54
- extraBabelPlugins: [
55
- ...(opts.beforeBabelPlugins || []),
56
- ...(opts.extraBabelPlugins || []),
57
- ],
58
- extraBabelPresets: [
59
- ...(opts.beforeBabelPresets || []),
60
- ...(opts.extraBabelPresets || []),
61
- ],
62
- modifyViteConfig: opts.modifyViteConfig,
63
- });
64
- const viteBuildConfig = (0, vite_1.mergeConfig)({
65
- root: opts.cwd,
66
- mode: types_1.Env.production,
67
- build: {
68
- // generate assets to publicPath dir
69
- assetsDir: path_1.default.relative('/', path_1.default.join('/', opts.config.publicPath || '')),
70
- rollupOptions: tmpHtmlEntry
71
- ? // first use entry from options
72
- {
73
- // use temp html entry for vite build
74
- input: tmpHtmlEntry,
75
- // remove temp html entry after build
76
- plugins: [
77
- (0, deleteOutputFiles_1.default)(Object.values(tmpHtmlEntry), (file) => {
78
- if (file.type === 'asset') {
79
- const $ = utils_1.cheerio.load(file.source);
80
- extraHtmlPart = {
81
- head: $('head').html(),
82
- body: $('body').html(),
83
- };
84
- }
85
- }),
86
- ],
87
- }
88
- : // fallback to vite default entry
89
- {},
90
- },
91
- }, viteUserConfig);
92
- try {
93
- result.stats = await (0, vite_1.build)(viteBuildConfig);
94
- result.stats.extraHtml = extraHtmlPart;
95
- result.time = +new Date() - startTms;
96
- }
97
- catch (err) {
98
- result.err = err;
71
+ let extraHtmlPart;
72
+ const startTms = +new Date();
73
+ const result = {
74
+ isFirstCompile: true,
75
+ time: 0
76
+ };
77
+ const tmpHtmlEntry = generateTempEntry(opts.cwd, opts.entry);
78
+ const viteUserConfig = await (0, import_config.getConfig)({
79
+ cwd: opts.cwd,
80
+ env: import_types.Env.production,
81
+ entry: opts.entry,
82
+ userConfig: opts.config,
83
+ extraBabelPlugins: [
84
+ ...opts.beforeBabelPlugins || [],
85
+ ...opts.extraBabelPlugins || []
86
+ ],
87
+ extraBabelPresets: [
88
+ ...opts.beforeBabelPresets || [],
89
+ ...opts.extraBabelPresets || []
90
+ ],
91
+ modifyViteConfig: opts.modifyViteConfig
92
+ });
93
+ const viteBuildConfig = (0, import_vite.mergeConfig)({
94
+ root: opts.cwd,
95
+ mode: import_types.Env.production,
96
+ build: {
97
+ assetsDir: import_path.default.relative("/", import_path.default.join("/", opts.config.publicPath || "")),
98
+ rollupOptions: tmpHtmlEntry ? {
99
+ input: tmpHtmlEntry,
100
+ plugins: [
101
+ (0, import_deleteOutputFiles.default)(Object.values(tmpHtmlEntry), (file) => {
102
+ if (file.type === "asset") {
103
+ const $ = import_utils.cheerio.load(file.source);
104
+ extraHtmlPart = {
105
+ head: $("head").html(),
106
+ body: $("body").html()
107
+ };
108
+ }
109
+ })
110
+ ]
111
+ } : {}
99
112
  }
100
- opts.onBuildComplete && opts.onBuildComplete(result);
113
+ }, viteUserConfig);
114
+ try {
115
+ result.stats = await (0, import_vite.build)(viteBuildConfig);
116
+ result.stats.extraHtml = extraHtmlPart;
117
+ result.time = +new Date() - startTms;
118
+ } catch (err) {
119
+ result.err = err;
120
+ }
121
+ opts.onBuildComplete && opts.onBuildComplete(result);
101
122
  }
102
- exports.build = build;
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ build
126
+ });
package/dist/cli.d.ts CHANGED
File without changes
package/dist/cli.js CHANGED
@@ -1,76 +1,84 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
4
14
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const esbuild_1 = __importDefault(require("@umijs/bundler-utils/compiled/esbuild"));
7
- const utils_1 = require("@umijs/utils");
8
- const assert_1 = __importDefault(require("assert"));
9
- const fs_1 = require("fs");
10
- const path_1 = require("path");
11
- const build_1 = require("./build");
12
- const dev_1 = require("./dev");
13
- const args = (0, utils_1.yParser)(process.argv.slice(2), {});
14
- const command = args._[0];
15
- const cwd = process.cwd();
16
- const entry = (0, utils_1.tryPaths)([
17
- (0, path_1.join)(cwd, 'src/index.tsx'),
18
- (0, path_1.join)(cwd, 'src/index.ts'),
19
- (0, path_1.join)(cwd, 'index.tsx'),
20
- (0, path_1.join)(cwd, 'index.ts'),
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
16
+
17
+ // cli.ts
18
+ var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
19
+ var import_utils = require("@umijs/utils");
20
+ var import_assert = __toESM(require("assert"));
21
+ var import_fs = require("fs");
22
+ var import_path = require("path");
23
+ var import_build = require("./build");
24
+ var import_dev = require("./dev");
25
+ var args = (0, import_utils.yParser)(process.argv.slice(2), {});
26
+ var command = args._[0];
27
+ var cwd = process.cwd();
28
+ var entry = (0, import_utils.tryPaths)([
29
+ (0, import_path.join)(cwd, "src/index.tsx"),
30
+ (0, import_path.join)(cwd, "src/index.ts"),
31
+ (0, import_path.join)(cwd, "index.tsx"),
32
+ (0, import_path.join)(cwd, "index.ts")
21
33
  ]);
22
- let config = {};
23
- const configFile = (0, path_1.join)(cwd, args.config || 'config.ts');
24
- utils_1.register.register({
25
- implementor: esbuild_1.default,
34
+ var config = {};
35
+ var configFile = (0, import_path.join)(cwd, args.config || "config.ts");
36
+ import_utils.register.register({
37
+ implementor: import_esbuild.default
26
38
  });
27
- utils_1.register.clearFiles();
28
- if ((0, fs_1.existsSync)(configFile)) {
29
- config = require(configFile).default;
39
+ import_utils.register.clearFiles();
40
+ if ((0, import_fs.existsSync)(configFile)) {
41
+ config = require(configFile).default;
30
42
  }
31
43
  Object.assign(config, args);
32
- if (command === 'build') {
33
- (async () => {
34
- process.env.NODE_ENV = 'production';
35
- (0, assert_1.default)(entry, `Build failed: entry not found.`);
36
- try {
37
- await (0, build_1.build)({
38
- config,
39
- cwd,
40
- entry: {
41
- [getEntryKey(entry)]: entry,
42
- },
43
- });
44
+ if (command === "build") {
45
+ (async () => {
46
+ process.env.NODE_ENV = "production";
47
+ (0, import_assert.default)(entry, `Build failed: entry not found.`);
48
+ try {
49
+ await (0, import_build.build)({
50
+ config,
51
+ cwd,
52
+ entry: {
53
+ [getEntryKey(entry)]: entry
44
54
  }
45
- catch (e) {
46
- console.error(e);
55
+ });
56
+ } catch (e) {
57
+ console.error(e);
58
+ }
59
+ })();
60
+ } else if (command === "dev") {
61
+ (async () => {
62
+ process.env.NODE_ENV = "development";
63
+ try {
64
+ (0, import_assert.default)(entry, `Build failed: entry not found.`);
65
+ await (0, import_dev.dev)({
66
+ config,
67
+ cwd,
68
+ entry: {
69
+ [getEntryKey(entry)]: entry
47
70
  }
48
- })();
49
- }
50
- else if (command === 'dev') {
51
- (async () => {
52
- process.env.NODE_ENV = 'development';
53
- try {
54
- (0, assert_1.default)(entry, `Build failed: entry not found.`);
55
- await (0, dev_1.dev)({
56
- config,
57
- cwd,
58
- entry: {
59
- [getEntryKey(entry)]: entry,
60
- },
61
- });
62
- }
63
- catch (e) {
64
- console.error(e);
65
- }
66
- })();
67
- }
68
- else {
69
- error(`Unsupported command ${command}.`);
71
+ });
72
+ } catch (e) {
73
+ console.error(e);
74
+ }
75
+ })();
76
+ } else {
77
+ error(`Unsupported command ${command}.`);
70
78
  }
71
79
  function error(msg) {
72
- console.error(utils_1.chalk.red(msg));
80
+ console.error(import_utils.chalk.red(msg));
73
81
  }
74
82
  function getEntryKey(path) {
75
- return (0, path_1.basename)(path, (0, path_1.extname)(path));
83
+ return (0, import_path.basename)(path, (0, import_path.extname)(path));
76
84
  }
File without changes
@@ -1,33 +1,73 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
4
27
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfig = void 0;
7
- const vite_1 = require("../../compiled/vite");
8
- const plugins_1 = __importDefault(require("../plugins"));
9
- const transformer_1 = __importDefault(require("./transformer"));
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // config.ts
40
+ var config_exports = {};
41
+ __export(config_exports, {
42
+ getConfig: () => getConfig
43
+ });
44
+ module.exports = __toCommonJS(config_exports);
45
+ var import_vite = require("../../compiled/vite");
46
+ var import_plugins = __toESM(require("../plugins"));
47
+ var import_transformer = __toESM(require("./transformer"));
10
48
  async function getConfig(opts) {
11
- const applyOpts = {
12
- ...opts.userConfig,
13
- entry: opts.entry,
14
- extraBabelPlugins: [
15
- ...(opts.extraBabelPlugins || []),
16
- ...(opts.userConfig.extraBabelPlugins || []),
17
- ],
18
- extraBabelPresets: [
19
- ...(opts.extraBabelPresets || []),
20
- ...(opts.userConfig.extraBabelPresets || []),
21
- ],
22
- };
23
- const vitePluginsConfig = (0, plugins_1.default)(applyOpts);
24
- const viteConfigFromUserConfig = (0, transformer_1.default)(applyOpts);
25
- let viteConfig = (0, vite_1.mergeConfig)(vitePluginsConfig, viteConfigFromUserConfig);
26
- if (opts.modifyViteConfig) {
27
- viteConfig = await opts.modifyViteConfig(viteConfig, {
28
- env: opts.env,
29
- });
30
- }
31
- return viteConfig;
49
+ const applyOpts = __spreadProps(__spreadValues({}, opts.userConfig), {
50
+ entry: opts.entry,
51
+ extraBabelPlugins: [
52
+ ...opts.extraBabelPlugins || [],
53
+ ...opts.userConfig.extraBabelPlugins || []
54
+ ],
55
+ extraBabelPresets: [
56
+ ...opts.extraBabelPresets || [],
57
+ ...opts.userConfig.extraBabelPresets || []
58
+ ]
59
+ });
60
+ const vitePluginsConfig = (0, import_plugins.default)(applyOpts);
61
+ const viteConfigFromUserConfig = (0, import_transformer.default)(applyOpts);
62
+ let viteConfig = (0, import_vite.mergeConfig)(vitePluginsConfig, viteConfigFromUserConfig);
63
+ if (opts.modifyViteConfig) {
64
+ viteConfig = await opts.modifyViteConfig(viteConfig, {
65
+ env: opts.env
66
+ });
67
+ }
68
+ return viteConfig;
32
69
  }
33
- exports.getConfig = getConfig;
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ getConfig
73
+ });
@@ -1,6 +1,6 @@
1
1
  import type { IConfigProcessor } from '.';
2
+ declare const _default: IConfigProcessor;
2
3
  /**
3
4
  * transform umi alias to vite alias
4
5
  */
5
- declare const _default: IConfigProcessor;
6
6
  export default _default;
@@ -1,50 +1,62 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function hoistAlias(alias) {
4
- function getFinalReplacement(oAlias, replacement, index) {
5
- //过滤重复配置,防止死循环
6
- const newAlias = oAlias.slice();
7
- newAlias.splice(index, 1);
8
- //遍历找到需要深层替换的配置
9
- for (let i = 0; i < newAlias.length; i++) {
10
- if (newAlias[i].find.test(replacement)) {
11
- replacement = replacement.replace(newAlias[i].find, newAlias[i].replacement);
12
- return getFinalReplacement(newAlias, replacement, i);
13
- }
14
- }
15
- return replacement;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // alias.ts
20
+ var alias_exports = {};
21
+ __export(alias_exports, {
22
+ default: () => alias_default
23
+ });
24
+ module.exports = __toCommonJS(alias_exports);
25
+ function hoistAlias(alias2) {
26
+ function getFinalReplacement(oAlias, replacement, index) {
27
+ const newAlias = oAlias.slice();
28
+ newAlias.splice(index, 1);
29
+ for (let i = 0; i < newAlias.length; i++) {
30
+ if (newAlias[i].find.test(replacement)) {
31
+ replacement = replacement.replace(newAlias[i].find, newAlias[i].replacement);
32
+ return getFinalReplacement(newAlias, replacement, i);
33
+ }
16
34
  }
17
- alias.forEach((rule, index, alias) => {
18
- rule.replacement = getFinalReplacement(alias, rule.replacement, index);
19
- });
20
- return alias;
35
+ return replacement;
36
+ }
37
+ alias2.forEach((rule, index, alias3) => {
38
+ rule.replacement = getFinalReplacement(alias3, rule.replacement, index);
39
+ });
40
+ return alias2;
21
41
  }
22
- /**
23
- * transform umi alias to vite alias
24
- */
25
- exports.default = (function alias(userConfig) {
26
- const config = {
27
- resolve: {
28
- alias: [
29
- // to support less-loader ~ for local deps, refer: https://github.com/vitejs/vite/issues/2185
30
- { find: /^~/, replacement: '' },
31
- ],
32
- },
33
- };
34
- // alias: { foo: bar } foo => bar, foo/hoo => bar/foo
35
- // alias: { foo$: bar } foo => bar, foo/hoo => foo/hoo
36
- if (userConfig.alias) {
37
- const userAlias = Object.entries(userConfig.alias).map(([name, target]) => ({
38
- // supports webpack suffix $ and less-loader prefix ~
39
- // example:
40
- // - dep => ^~?dep(?=\/|$)
41
- // - dep$ => ^~?dep$
42
- find: new RegExp(`^~?${name.replace(/(?<!\$)$/, '(?=/|$)')}`),
43
- replacement: target,
44
- }));
45
- const wholeAlias = config.resolve.alias;
46
- wholeAlias.unshift(...userAlias);
47
- config.resolve.alias = hoistAlias(wholeAlias);
42
+ var alias_default = function alias(userConfig) {
43
+ const config = {
44
+ resolve: {
45
+ alias: [
46
+ { find: /^~/, replacement: "" }
47
+ ]
48
48
  }
49
- return config;
50
- });
49
+ };
50
+ if (userConfig.alias) {
51
+ const userAlias = Object.entries(userConfig.alias).map(([name, target]) => ({
52
+ find: new RegExp(`^~?${name.replace(/(?<!\$)$/, "(?=/|$)")}`),
53
+ replacement: target
54
+ }));
55
+ const wholeAlias = config.resolve.alias;
56
+ wholeAlias.unshift(...userAlias);
57
+ config.resolve.alias = hoistAlias(wholeAlias);
58
+ }
59
+ return config;
60
+ };
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {});
@@ -1,5 +1,6 @@
1
1
  import type { IConfigProcessor } from '.';
2
2
  export declare function getBrowserlist(targets: Record<string, string | boolean>): string | string[];
3
+ declare const _default: IConfigProcessor;
3
4
  /**
4
5
  * transform umi css pre-processor configs to vite postcss config
5
6
  * @note include configs:
@@ -10,5 +11,4 @@ export declare function getBrowserlist(targets: Record<string, string | boolean>
10
11
  * - lessLoader
11
12
  * - theme
12
13
  */
13
- declare const _default: IConfigProcessor;
14
14
  export default _default;