@umijs/bundler-vite 4.2.6-alpha.6 → 4.2.6
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.
- package/dist/build.d.ts +15 -0
- package/dist/build.js +138 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +91 -0
- package/dist/config/config.d.ts +13 -0
- package/dist/config/config.js +64 -0
- package/dist/config/transformer/alias.d.ts +6 -0
- package/dist/config/transformer/alias.js +70 -0
- package/dist/config/transformer/css.d.ts +14 -0
- package/dist/config/transformer/css.js +67 -0
- package/dist/config/transformer/define.d.ts +6 -0
- package/dist/config/transformer/define.js +33 -0
- package/dist/config/transformer/index.d.ts +11 -0
- package/dist/config/transformer/index.js +62 -0
- package/dist/config/transformer/merge.d.ts +6 -0
- package/dist/config/transformer/merge.js +29 -0
- package/dist/config/transformer/optimizeDeps.d.ts +6 -0
- package/dist/config/transformer/optimizeDeps.js +36 -0
- package/dist/config/transformer/react.d.ts +6 -0
- package/dist/config/transformer/react.js +55 -0
- package/dist/config/transformer/rename.d.ts +6 -0
- package/dist/config/transformer/rename.js +54 -0
- package/dist/config/transformer/rollup.d.ts +11 -0
- package/dist/config/transformer/rollup.js +106 -0
- package/dist/config/transformer/target.d.ts +6 -0
- package/dist/config/transformer/target.js +69 -0
- package/dist/dev.d.ts +19 -0
- package/dist/dev.js +59 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -0
- package/dist/plugins/autoCSSModule.d.ts +6 -0
- package/dist/plugins/autoCSSModule.js +42 -0
- package/dist/plugins/deleteOutputFiles.d.ts +8 -0
- package/dist/plugins/deleteOutputFiles.js +39 -0
- package/dist/plugins/externals.d.ts +7 -0
- package/dist/plugins/externals.js +39 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.js +46 -0
- package/dist/plugins/svgr.d.ts +16 -0
- package/dist/plugins/svgr.js +76 -0
- package/dist/requireHook.d.ts +1 -0
- package/dist/requireHook.js +12 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +83 -0
- package/dist/server/plugins/onHotUpdate.d.ts +2 -0
- package/dist/server/plugins/onHotUpdate.js +33 -0
- package/dist/server/server.d.ts +29 -0
- package/dist/server/server.js +120 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.js +41 -0
- package/package.json +3 -3
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IBabelPlugin, IConfig } from './types';
|
|
2
|
+
interface IOpts {
|
|
3
|
+
cwd: string;
|
|
4
|
+
entry: Record<string, string>;
|
|
5
|
+
config: IConfig;
|
|
6
|
+
onBuildComplete?: Function;
|
|
7
|
+
clean?: boolean;
|
|
8
|
+
beforeBabelPlugins?: any[];
|
|
9
|
+
beforeBabelPresets?: any[];
|
|
10
|
+
extraBabelPlugins?: IBabelPlugin[];
|
|
11
|
+
extraBabelPresets?: IBabelPlugin[];
|
|
12
|
+
modifyViteConfig?: Function;
|
|
13
|
+
}
|
|
14
|
+
export declare function build(opts: IOpts): Promise<void>;
|
|
15
|
+
export {};
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
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 __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/build.ts
|
|
30
|
+
var build_exports = {};
|
|
31
|
+
__export(build_exports, {
|
|
32
|
+
build: () => build
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(build_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_vite = require("../compiled/vite");
|
|
39
|
+
var import_config = require("./config/config");
|
|
40
|
+
var import_deleteOutputFiles = __toESM(require("./plugins/deleteOutputFiles"));
|
|
41
|
+
var import_types = require("./types");
|
|
42
|
+
function getUmiTmpDir(cwd, entry) {
|
|
43
|
+
const mainEntry = Object.values(entry).find((p) => p.includes("/umi.ts"));
|
|
44
|
+
if (!mainEntry) {
|
|
45
|
+
const tmp = import_path.default.join(cwd, "node_modules/.tmp");
|
|
46
|
+
return tmp;
|
|
47
|
+
}
|
|
48
|
+
return import_path.default.dirname(mainEntry);
|
|
49
|
+
}
|
|
50
|
+
function generateTempEntry(cwd, entry) {
|
|
51
|
+
if (process.env.UMI_CLI_TEST) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const umiTmpDir = getUmiTmpDir(cwd, entry);
|
|
55
|
+
if (umiTmpDir) {
|
|
56
|
+
const entryTmpDir = import_path.default.join(umiTmpDir, ".bundler-vite-entry");
|
|
57
|
+
import_utils.fsExtra.ensureDirSync(entryTmpDir);
|
|
58
|
+
return Object.keys(entry).reduce((r, name) => {
|
|
59
|
+
const entryFilePath = import_path.default.join(entryTmpDir, `${name}.html`);
|
|
60
|
+
import_fs.default.writeFileSync(
|
|
61
|
+
entryFilePath,
|
|
62
|
+
`<html><head></head><body><script type="module" src="${entry[name]}"></script></body></html>`,
|
|
63
|
+
"utf8"
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
...r,
|
|
67
|
+
[name]: import_path.default.relative(cwd, entryFilePath)
|
|
68
|
+
};
|
|
69
|
+
}, {});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function build(opts) {
|
|
73
|
+
let extraHtmlPart;
|
|
74
|
+
const startTms = +/* @__PURE__ */ new Date();
|
|
75
|
+
const result = {
|
|
76
|
+
isFirstCompile: true,
|
|
77
|
+
time: 0
|
|
78
|
+
};
|
|
79
|
+
const tmpHtmlEntry = generateTempEntry(opts.cwd, opts.entry);
|
|
80
|
+
const viteUserConfig = await (0, import_config.getConfig)({
|
|
81
|
+
cwd: opts.cwd,
|
|
82
|
+
env: import_types.Env.production,
|
|
83
|
+
entry: opts.entry,
|
|
84
|
+
userConfig: opts.config,
|
|
85
|
+
extraBabelPlugins: [
|
|
86
|
+
...opts.beforeBabelPlugins || [],
|
|
87
|
+
...opts.extraBabelPlugins || []
|
|
88
|
+
],
|
|
89
|
+
extraBabelPresets: [
|
|
90
|
+
...opts.beforeBabelPresets || [],
|
|
91
|
+
...opts.extraBabelPresets || []
|
|
92
|
+
],
|
|
93
|
+
modifyViteConfig: opts.modifyViteConfig
|
|
94
|
+
});
|
|
95
|
+
const viteBuildConfig = (0, import_vite.mergeConfig)(
|
|
96
|
+
{
|
|
97
|
+
root: opts.cwd,
|
|
98
|
+
mode: import_types.Env.production,
|
|
99
|
+
build: {
|
|
100
|
+
rollupOptions: tmpHtmlEntry ? (
|
|
101
|
+
// first use entry from options
|
|
102
|
+
{
|
|
103
|
+
// use temp html entry for vite build
|
|
104
|
+
input: tmpHtmlEntry,
|
|
105
|
+
// remove temp html entry after build
|
|
106
|
+
plugins: [
|
|
107
|
+
(0, import_deleteOutputFiles.default)(Object.values(tmpHtmlEntry), (file) => {
|
|
108
|
+
if (file.type === "asset") {
|
|
109
|
+
const $ = import_utils.cheerio.load(file.source);
|
|
110
|
+
extraHtmlPart = {
|
|
111
|
+
head: $("head").html(),
|
|
112
|
+
body: $("body").html()
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
) : (
|
|
119
|
+
// fallback to vite default entry
|
|
120
|
+
{}
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
viteUserConfig
|
|
125
|
+
);
|
|
126
|
+
try {
|
|
127
|
+
result.stats = await (0, import_vite.build)(viteBuildConfig);
|
|
128
|
+
result.stats.extraHtml = extraHtmlPart;
|
|
129
|
+
result.time = +/* @__PURE__ */ new Date() - startTms;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
result.err = err;
|
|
132
|
+
}
|
|
133
|
+
opts.onBuildComplete && opts.onBuildComplete(result);
|
|
134
|
+
}
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
build
|
|
138
|
+
});
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
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;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
|
|
24
|
+
// src/cli.ts
|
|
25
|
+
var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
26
|
+
var import_utils = require("@umijs/utils");
|
|
27
|
+
var import_assert = __toESM(require("assert"));
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
var import_build = require("./build");
|
|
31
|
+
var import_dev = require("./dev");
|
|
32
|
+
var args = (0, import_utils.yParser)(process.argv.slice(2), {});
|
|
33
|
+
var command = args._[0];
|
|
34
|
+
var cwd = process.cwd();
|
|
35
|
+
var entry = (0, import_utils.tryPaths)([
|
|
36
|
+
(0, import_path.join)(cwd, "src/index.tsx"),
|
|
37
|
+
(0, import_path.join)(cwd, "src/index.ts"),
|
|
38
|
+
(0, import_path.join)(cwd, "index.tsx"),
|
|
39
|
+
(0, import_path.join)(cwd, "index.ts")
|
|
40
|
+
]);
|
|
41
|
+
var config = {};
|
|
42
|
+
var configFile = (0, import_path.join)(cwd, args.config || "config.ts");
|
|
43
|
+
import_utils.register.register({
|
|
44
|
+
implementor: import_esbuild.default
|
|
45
|
+
});
|
|
46
|
+
import_utils.register.clearFiles();
|
|
47
|
+
if ((0, import_fs.existsSync)(configFile)) {
|
|
48
|
+
config = require(configFile).default;
|
|
49
|
+
}
|
|
50
|
+
Object.assign(config, args);
|
|
51
|
+
if (command === "build") {
|
|
52
|
+
(async () => {
|
|
53
|
+
process.env.NODE_ENV = "production";
|
|
54
|
+
(0, import_assert.default)(entry, `Build failed: entry not found.`);
|
|
55
|
+
try {
|
|
56
|
+
await (0, import_build.build)({
|
|
57
|
+
config,
|
|
58
|
+
cwd,
|
|
59
|
+
entry: {
|
|
60
|
+
[getEntryKey(entry)]: entry
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error(e);
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
} else if (command === "dev") {
|
|
68
|
+
(async () => {
|
|
69
|
+
process.env.NODE_ENV = "development";
|
|
70
|
+
try {
|
|
71
|
+
(0, import_assert.default)(entry, `Build failed: entry not found.`);
|
|
72
|
+
await (0, import_dev.dev)({
|
|
73
|
+
config,
|
|
74
|
+
cwd,
|
|
75
|
+
entry: {
|
|
76
|
+
[getEntryKey(entry)]: entry
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.error(e);
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
} else {
|
|
84
|
+
error(`Unsupported command ${command}.`);
|
|
85
|
+
}
|
|
86
|
+
function error(msg) {
|
|
87
|
+
console.error(import_utils.chalk.red(msg));
|
|
88
|
+
}
|
|
89
|
+
function getEntryKey(path) {
|
|
90
|
+
return (0, import_path.basename)(path, (0, import_path.extname)(path));
|
|
91
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { InlineConfig as ViteInlineConfig } from '../../compiled/vite';
|
|
2
|
+
import { Env, IBabelPlugin, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
cwd: string;
|
|
5
|
+
env: Env;
|
|
6
|
+
entry: Record<string, string>;
|
|
7
|
+
userConfig: IConfig;
|
|
8
|
+
modifyViteConfig?: Function;
|
|
9
|
+
extraBabelPlugins?: IBabelPlugin[];
|
|
10
|
+
extraBabelPresets?: IBabelPlugin[];
|
|
11
|
+
}
|
|
12
|
+
export declare function getConfig(opts: IOpts): Promise<ViteInlineConfig>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
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 __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/config/config.ts
|
|
30
|
+
var config_exports = {};
|
|
31
|
+
__export(config_exports, {
|
|
32
|
+
getConfig: () => getConfig
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(config_exports);
|
|
35
|
+
var import_vite = require("../../compiled/vite");
|
|
36
|
+
var import_plugins = __toESM(require("../plugins"));
|
|
37
|
+
var import_transformer = __toESM(require("./transformer"));
|
|
38
|
+
async function getConfig(opts) {
|
|
39
|
+
const applyOpts = {
|
|
40
|
+
...opts.userConfig,
|
|
41
|
+
entry: opts.entry,
|
|
42
|
+
extraBabelPlugins: [
|
|
43
|
+
...opts.extraBabelPlugins || [],
|
|
44
|
+
...opts.userConfig.extraBabelPlugins || []
|
|
45
|
+
],
|
|
46
|
+
extraBabelPresets: [
|
|
47
|
+
...opts.extraBabelPresets || [],
|
|
48
|
+
...opts.userConfig.extraBabelPresets || []
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
const vitePluginsConfig = (0, import_plugins.default)(applyOpts);
|
|
52
|
+
const viteConfigFromUserConfig = (0, import_transformer.default)(applyOpts);
|
|
53
|
+
let viteConfig = (0, import_vite.mergeConfig)(vitePluginsConfig, viteConfigFromUserConfig);
|
|
54
|
+
if (opts.modifyViteConfig) {
|
|
55
|
+
viteConfig = await opts.modifyViteConfig(viteConfig, {
|
|
56
|
+
env: opts.env
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return viteConfig;
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
getConfig
|
|
64
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
// src/config/transformer/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(
|
|
32
|
+
newAlias[i].find,
|
|
33
|
+
newAlias[i].replacement
|
|
34
|
+
);
|
|
35
|
+
return getFinalReplacement(newAlias, replacement, i);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return replacement;
|
|
39
|
+
}
|
|
40
|
+
alias2.forEach((rule, index, alias3) => {
|
|
41
|
+
rule.replacement = getFinalReplacement(alias3, rule.replacement, index);
|
|
42
|
+
});
|
|
43
|
+
return alias2;
|
|
44
|
+
}
|
|
45
|
+
var alias_default = function alias(userConfig) {
|
|
46
|
+
const config = {
|
|
47
|
+
resolve: {
|
|
48
|
+
alias: [
|
|
49
|
+
// to support less-loader ~ for local deps, refer: https://github.com/vitejs/vite/issues/2185
|
|
50
|
+
{ find: /^~/, replacement: "" }
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (userConfig.alias) {
|
|
55
|
+
const userAlias = Object.entries(userConfig.alias).map(
|
|
56
|
+
([name, target]) => ({
|
|
57
|
+
// supports webpack suffix $ and less-loader prefix ~
|
|
58
|
+
// example:
|
|
59
|
+
// - dep => ^~?dep(?=\/|$)
|
|
60
|
+
// - dep$ => ^~?dep$
|
|
61
|
+
find: new RegExp(`^~?${name.replace(/(?<!\$)$/, "(?=/|$)")}`),
|
|
62
|
+
replacement: target
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
const wholeAlias = config.resolve.alias;
|
|
66
|
+
wholeAlias.unshift(...userAlias);
|
|
67
|
+
config.resolve.alias = hoistAlias(wholeAlias);
|
|
68
|
+
}
|
|
69
|
+
return config;
|
|
70
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IConfigProcessor } from '.';
|
|
2
|
+
export declare function getBrowserlist(targets: Record<string, string | boolean>): string | string[];
|
|
3
|
+
/**
|
|
4
|
+
* transform umi css pre-processor configs to vite postcss config
|
|
5
|
+
* @note include configs:
|
|
6
|
+
* - postcssLoader
|
|
7
|
+
* - targets (css only)
|
|
8
|
+
* - autoprefixer
|
|
9
|
+
* - extraPostCSSPlugins
|
|
10
|
+
* - lessLoader
|
|
11
|
+
* - theme
|
|
12
|
+
*/
|
|
13
|
+
declare const _default: IConfigProcessor;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
// src/config/transformer/css.ts
|
|
20
|
+
var css_exports = {};
|
|
21
|
+
__export(css_exports, {
|
|
22
|
+
default: () => css_default,
|
|
23
|
+
getBrowserlist: () => getBrowserlist
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(css_exports);
|
|
26
|
+
function getBrowserlist(targets) {
|
|
27
|
+
return typeof targets.browsers === "string" ? targets.browser : Object.keys(targets).map(
|
|
28
|
+
(key) => `${key} >= ${targets[key] === true ? "0" : targets[key]}`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
var css_default = function css(userConfig) {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
const config = {
|
|
34
|
+
css: { postcss: {}, preprocessorOptions: {} }
|
|
35
|
+
};
|
|
36
|
+
config.css.postcss = {
|
|
37
|
+
// handle postcssLoader
|
|
38
|
+
...((_a = userConfig.postcssLoader) == null ? void 0 : _a.postcssOptions) || {},
|
|
39
|
+
plugins: [
|
|
40
|
+
...((_c = (_b = userConfig.postcssLoader) == null ? void 0 : _b.postcssOptions) == null ? void 0 : _c.plugins) || [],
|
|
41
|
+
require("postcss-preset-env")({
|
|
42
|
+
// handle targets for css
|
|
43
|
+
browsers: getBrowserlist(userConfig.targets || {}),
|
|
44
|
+
// handle autoprefixer
|
|
45
|
+
autoprefixer: {
|
|
46
|
+
flexbox: "no-2009",
|
|
47
|
+
...userConfig.autoprefixer || {}
|
|
48
|
+
},
|
|
49
|
+
stage: 3
|
|
50
|
+
}),
|
|
51
|
+
// handle extraPostCSSPlugins
|
|
52
|
+
...userConfig.extraPostCSSPlugins || []
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
config.css.preprocessorOptions.less = {
|
|
56
|
+
javascriptEnabled: true,
|
|
57
|
+
// handle lessLoader
|
|
58
|
+
...((_d = userConfig.lessLoader) == null ? void 0 : _d.lessOptions) || {},
|
|
59
|
+
// handle theme
|
|
60
|
+
modifyVars: userConfig.theme || {}
|
|
61
|
+
};
|
|
62
|
+
return config;
|
|
63
|
+
};
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
getBrowserlist
|
|
67
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
// src/config/transformer/define.ts
|
|
20
|
+
var define_exports = {};
|
|
21
|
+
__export(define_exports, {
|
|
22
|
+
default: () => define_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(define_exports);
|
|
25
|
+
var define_default = function define(userConfig) {
|
|
26
|
+
const config = { define: {} };
|
|
27
|
+
if (typeof userConfig.define === "object") {
|
|
28
|
+
Object.keys(userConfig.define).forEach((name) => {
|
|
29
|
+
config.define[name] = JSON.stringify(userConfig.define[name]);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return config;
|
|
33
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InlineConfig as ViteInlineConfig } from '../../../compiled/vite';
|
|
2
|
+
declare type ITmpUserConfig = Record<string, any>;
|
|
3
|
+
/**
|
|
4
|
+
* type of config processor
|
|
5
|
+
*/
|
|
6
|
+
export declare type IConfigProcessor = (userConfig: ITmpUserConfig, currentViteConfig: Partial<ViteInlineConfig>) => Partial<ViteInlineConfig>;
|
|
7
|
+
/**
|
|
8
|
+
* config transformer
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: (userConfig: ITmpUserConfig) => ViteInlineConfig;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 __export = (target2, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/config/transformer/index.ts
|
|
30
|
+
var transformer_exports = {};
|
|
31
|
+
__export(transformer_exports, {
|
|
32
|
+
default: () => transformer_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(transformer_exports);
|
|
35
|
+
var import_vite = require("../../../compiled/vite");
|
|
36
|
+
var import_alias = __toESM(require("./alias"));
|
|
37
|
+
var import_css = __toESM(require("./css"));
|
|
38
|
+
var import_define = __toESM(require("./define"));
|
|
39
|
+
var import_merge = __toESM(require("./merge"));
|
|
40
|
+
var import_optimizeDeps = __toESM(require("./optimizeDeps"));
|
|
41
|
+
var import_react = __toESM(require("./react"));
|
|
42
|
+
var import_rename = __toESM(require("./rename"));
|
|
43
|
+
var import_rollup = __toESM(require("./rollup"));
|
|
44
|
+
var import_target = __toESM(require("./target"));
|
|
45
|
+
var transformer_default = (userConfig) => {
|
|
46
|
+
const transformers = [
|
|
47
|
+
import_rename.default,
|
|
48
|
+
import_alias.default,
|
|
49
|
+
// must before css for support ~ prefix from less-loader
|
|
50
|
+
import_css.default,
|
|
51
|
+
import_rollup.default,
|
|
52
|
+
import_react.default,
|
|
53
|
+
import_optimizeDeps.default,
|
|
54
|
+
import_target.default,
|
|
55
|
+
import_define.default,
|
|
56
|
+
import_merge.default
|
|
57
|
+
];
|
|
58
|
+
return transformers.reduce(
|
|
59
|
+
(memo, transformer) => (0, import_vite.mergeConfig)(memo, transformer(userConfig, memo)),
|
|
60
|
+
{}
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
// src/config/transformer/merge.ts
|
|
20
|
+
var merge_exports = {};
|
|
21
|
+
__export(merge_exports, {
|
|
22
|
+
default: () => merge_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(merge_exports);
|
|
25
|
+
var merge_default = function merge(userConfig) {
|
|
26
|
+
if (typeof userConfig.vite === "object") {
|
|
27
|
+
return userConfig.vite;
|
|
28
|
+
}
|
|
29
|
+
};
|