@umijs/bundler-esbuild 4.0.0-beta.9 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/dist/build.d.ts +2 -2
- package/dist/build.js +97 -56
- package/dist/cli.js +63 -61
- package/dist/index.js +22 -12
- package/dist/plugins/__sample.js +30 -5
- package/dist/plugins/alias.js +89 -65
- package/dist/plugins/externals.d.ts +1 -1
- package/dist/plugins/externals.js +43 -21
- package/dist/plugins/less-plugin-alias/index.d.ts +9 -0
- package/dist/plugins/less-plugin-alias/index.js +100 -0
- package/dist/plugins/less-plugin-alias/types.d.ts +4 -0
- package/dist/plugins/less-plugin-alias/types.js +17 -0
- package/dist/plugins/less-plugin-alias/utils.d.ts +2 -0
- package/dist/plugins/less-plugin-alias/utils.js +60 -0
- package/dist/plugins/less.d.ts +7 -2
- package/dist/plugins/less.js +203 -49
- package/dist/plugins/nodeGlobalsPolyfill.js +36 -12
- package/dist/plugins/style.d.ts +4 -1
- package/dist/plugins/style.js +166 -78
- package/dist/plugins/watchRebuild.d.ts +4 -0
- package/dist/plugins/watchRebuild.js +67 -0
- package/dist/types.d.ts +11 -3
- package/dist/types.js +40 -13
- package/dist/utils/getBrowserlist.d.ts +1 -0
- package/dist/utils/getBrowserlist.js +33 -0
- package/dist/utils/postcssProcess.d.ts +2 -0
- package/dist/utils/postcssProcess.js +58 -0
- package/dist/utils/sortByAffix.js +38 -14
- package/package.json +19 -16
|
@@ -1,22 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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/plugins/externals.ts
|
|
20
|
+
var externals_exports = {};
|
|
21
|
+
__export(externals_exports, {
|
|
22
|
+
default: () => externals_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(externals_exports);
|
|
25
|
+
var externals_default = (options) => {
|
|
26
|
+
return {
|
|
27
|
+
name: "externals",
|
|
28
|
+
setup({ onLoad, onResolve }) {
|
|
29
|
+
if (!options || Object.keys(options).length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
Object.keys(options).forEach((key) => {
|
|
33
|
+
onResolve({ filter: new RegExp(`^${key}$`) }, (args) => ({
|
|
34
|
+
path: args.path,
|
|
35
|
+
namespace: key
|
|
36
|
+
}));
|
|
37
|
+
onLoad({ filter: /.*/, namespace: key }, () => ({
|
|
38
|
+
contents: `module.export=${options[key]}`,
|
|
39
|
+
loader: "js"
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
22
44
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
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/plugins/less-plugin-alias/index.ts
|
|
20
|
+
var less_plugin_alias_exports = {};
|
|
21
|
+
__export(less_plugin_alias_exports, {
|
|
22
|
+
default: () => LessAliasPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(less_plugin_alias_exports);
|
|
25
|
+
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_utils2 = require("./utils");
|
|
27
|
+
function matches(pattern, importee) {
|
|
28
|
+
if (pattern instanceof RegExp) {
|
|
29
|
+
return pattern.test(importee);
|
|
30
|
+
}
|
|
31
|
+
if (importee.length < pattern.length) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (importee === pattern) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return importee.startsWith(pattern + "/");
|
|
38
|
+
}
|
|
39
|
+
var LessAliasPlugin = class {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.options = options;
|
|
42
|
+
}
|
|
43
|
+
install(less, pluginManager) {
|
|
44
|
+
const alias = (0, import_utils2.parseAlias)(this.options.alias);
|
|
45
|
+
function resolveId(filename) {
|
|
46
|
+
if (!filename) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const matchedEntry = alias.find((entry) => matches(entry.find, filename));
|
|
50
|
+
if (!matchedEntry) {
|
|
51
|
+
return filename;
|
|
52
|
+
}
|
|
53
|
+
const resolvedPath = filename.replace(
|
|
54
|
+
matchedEntry.find,
|
|
55
|
+
matchedEntry.replacement
|
|
56
|
+
);
|
|
57
|
+
return resolvedPath;
|
|
58
|
+
}
|
|
59
|
+
class AliasePlugin extends less.FileManager {
|
|
60
|
+
loadFile(filename, currentDirectory, options, enviroment) {
|
|
61
|
+
let resolved;
|
|
62
|
+
try {
|
|
63
|
+
resolved = resolveId(filename);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
import_utils.logger.error(error);
|
|
66
|
+
}
|
|
67
|
+
if (!resolved) {
|
|
68
|
+
const error = new Error(
|
|
69
|
+
`[less-plugin-alias]: '${filename}' not found.`
|
|
70
|
+
);
|
|
71
|
+
import_utils.logger.error(error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
return super.loadFile(resolved, currentDirectory, options, enviroment);
|
|
75
|
+
}
|
|
76
|
+
loadFileSync(filename, currentDirectory, options, enviroment) {
|
|
77
|
+
let resolved;
|
|
78
|
+
try {
|
|
79
|
+
resolved = resolveId(filename);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
import_utils.logger.error(error);
|
|
82
|
+
}
|
|
83
|
+
if (!resolved) {
|
|
84
|
+
const error = new Error(
|
|
85
|
+
`[less-plugin-alias]: '${filename}' not found.`
|
|
86
|
+
);
|
|
87
|
+
import_utils.logger.error(error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
return super.loadFileSync(
|
|
91
|
+
resolved,
|
|
92
|
+
currentDirectory,
|
|
93
|
+
options,
|
|
94
|
+
enviroment
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
pluginManager.addFileManager(new AliasePlugin());
|
|
99
|
+
}
|
|
100
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/plugins/less-plugin-alias/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
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/plugins/less-plugin-alias/utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
parseAlias: () => parseAlias
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
25
|
+
function hoistAlias(alias) {
|
|
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
|
+
alias.forEach((rule, index, alias2) => {
|
|
41
|
+
rule.replacement = getFinalReplacement(alias2, rule.replacement, index);
|
|
42
|
+
});
|
|
43
|
+
return alias;
|
|
44
|
+
}
|
|
45
|
+
function parseAlias(alias) {
|
|
46
|
+
const wholeAlias = [
|
|
47
|
+
// to support less-loader ~ for local deps, refer: https://github.com/vitejs/vite/issues/2185
|
|
48
|
+
{ find: /^~/, replacement: "" }
|
|
49
|
+
];
|
|
50
|
+
const userAlias = Object.entries(alias).map(([name, target]) => ({
|
|
51
|
+
find: new RegExp(`^~?${name.replace(/(?<!\$)$/, "(?=/|$)")}`),
|
|
52
|
+
replacement: target
|
|
53
|
+
}));
|
|
54
|
+
wholeAlias.unshift(...userAlias);
|
|
55
|
+
return hoistAlias(wholeAlias);
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
parseAlias
|
|
60
|
+
});
|
package/dist/plugins/less.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/// <reference types="less" />
|
|
2
1
|
import { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
|
|
3
|
-
|
|
2
|
+
import { IConfig } from '../types';
|
|
3
|
+
export declare const aliasLessImportPath: (filePath: string, alias: Record<string, string>, importer: string) => Promise<string | null>;
|
|
4
|
+
declare const _default: (options?: Less.Options & {
|
|
5
|
+
alias?: Record<string, string>;
|
|
6
|
+
inlineStyle?: boolean;
|
|
7
|
+
config?: IConfig;
|
|
8
|
+
}) => Plugin;
|
|
4
9
|
export default _default;
|
package/dist/plugins/less.js
CHANGED
|
@@ -1,53 +1,207 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
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
10
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
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;
|
|
13
18
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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/plugins/less.ts
|
|
30
|
+
var less_exports = {};
|
|
31
|
+
__export(less_exports, {
|
|
32
|
+
aliasLessImportPath: () => aliasLessImportPath,
|
|
33
|
+
default: () => less_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(less_exports);
|
|
36
|
+
var import_less = __toESM(require("@umijs/bundler-utils/compiled/less"));
|
|
37
|
+
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
38
|
+
var import_fs = require("fs");
|
|
39
|
+
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_postcssProcess = require("../utils/postcssProcess");
|
|
41
|
+
var import_sortByAffix = require("../utils/sortByAffix");
|
|
42
|
+
var import_less_plugin_alias = __toESM(require("./less-plugin-alias"));
|
|
43
|
+
var resolver = import_enhanced_resolve.default.create({
|
|
44
|
+
mainFields: ["module", "browser", "main"],
|
|
45
|
+
extensions: [
|
|
46
|
+
".json",
|
|
47
|
+
".js",
|
|
48
|
+
".jsx",
|
|
49
|
+
".ts",
|
|
50
|
+
".tsx",
|
|
51
|
+
".cjs",
|
|
52
|
+
".mjs",
|
|
53
|
+
".less",
|
|
54
|
+
".css"
|
|
55
|
+
],
|
|
56
|
+
// TODO: support exports
|
|
57
|
+
exportsFields: []
|
|
58
|
+
});
|
|
59
|
+
async function resolve(context, path2) {
|
|
60
|
+
return new Promise((resolve2, reject) => {
|
|
61
|
+
resolver(
|
|
62
|
+
context,
|
|
63
|
+
path2,
|
|
64
|
+
(err, result) => err ? reject(err) : resolve2(result)
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
var aliasLessImports = async (ctx, alias, importer) => {
|
|
69
|
+
const importRegex = /@import(?:\s+\((.*)\))?\s+['"](.*)['"]/;
|
|
70
|
+
const globalImportRegex = /@import(?:\s+\((.*)\))?\s+['"](.*)['"]/g;
|
|
71
|
+
const match = ctx.match(globalImportRegex) || [];
|
|
72
|
+
for (const el of match) {
|
|
73
|
+
const [imp, _, filePath] = el.match(importRegex) || [];
|
|
74
|
+
let aliaPath = await aliasLessImportPath(filePath, alias, importer);
|
|
75
|
+
if (aliaPath) {
|
|
76
|
+
ctx = ctx.replace(imp, el.replace(filePath, aliaPath));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return ctx;
|
|
80
|
+
};
|
|
81
|
+
var aliasLessImportPath = async (filePath, alias, importer) => {
|
|
82
|
+
let aliaPath = filePath.startsWith("~") ? filePath.replace("~", "") : filePath;
|
|
83
|
+
const keys = (0, import_sortByAffix.sortByAffix)({ arr: Object.keys(alias), affix: "$" });
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
const pathSegments = aliaPath.split("/");
|
|
86
|
+
if (pathSegments[0] === key) {
|
|
87
|
+
pathSegments[0] = alias[key];
|
|
88
|
+
aliaPath = pathSegments.join("/");
|
|
89
|
+
aliaPath = import_path.default.extname(aliaPath) ? aliaPath : `${aliaPath}.less`;
|
|
90
|
+
return await resolve(importer, aliaPath);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
};
|
|
95
|
+
var less_default = (options = {}) => {
|
|
96
|
+
const { alias, inlineStyle, config, ...lessOptions } = options;
|
|
97
|
+
return {
|
|
98
|
+
name: "less",
|
|
99
|
+
setup({ onResolve, onLoad }) {
|
|
100
|
+
onResolve({ filter: /\.less$/, namespace: "file" }, async (args) => {
|
|
101
|
+
let filePath = args.path;
|
|
102
|
+
let isMatchedAlias = false;
|
|
103
|
+
if (!!alias) {
|
|
104
|
+
const aliasMatchPath = await aliasLessImportPath(
|
|
105
|
+
filePath,
|
|
106
|
+
alias,
|
|
107
|
+
args.path
|
|
108
|
+
);
|
|
109
|
+
if (aliasMatchPath) {
|
|
110
|
+
isMatchedAlias = true;
|
|
111
|
+
filePath = aliasMatchPath;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!isMatchedAlias) {
|
|
115
|
+
const isImportFromDeps = !import_path.default.isAbsolute(filePath) && !filePath.startsWith(".");
|
|
116
|
+
if (isImportFromDeps) {
|
|
117
|
+
filePath = await resolve(process.cwd(), filePath);
|
|
118
|
+
} else {
|
|
119
|
+
filePath = import_path.default.resolve(
|
|
120
|
+
process.cwd(),
|
|
121
|
+
import_path.default.relative(process.cwd(), args.resolveDir),
|
|
122
|
+
args.path
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
path: filePath,
|
|
128
|
+
namespace: inlineStyle ? "less-file" : "file"
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
if (inlineStyle) {
|
|
132
|
+
onResolve({ filter: /\.less$/, namespace: "less-file" }, (args) => {
|
|
133
|
+
return { path: args.path, namespace: "less-content" };
|
|
134
|
+
});
|
|
135
|
+
onResolve(
|
|
136
|
+
{ filter: /^__style_helper__$/, namespace: "less-file" },
|
|
137
|
+
(args) => ({
|
|
138
|
+
path: args.path,
|
|
139
|
+
namespace: "style-helper",
|
|
140
|
+
sideEffects: false
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
onLoad({ filter: /.*/, namespace: "less-file" }, async (args) => ({
|
|
144
|
+
contents: `
|
|
145
|
+
import { injectStyle } from "__style_helper__"
|
|
146
|
+
import css from ${JSON.stringify(args.path)}
|
|
147
|
+
injectStyle(css)
|
|
148
|
+
export default{}
|
|
149
|
+
`
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
onLoad(
|
|
153
|
+
{ filter: /\.less$/, namespace: inlineStyle ? "less-content" : "file" },
|
|
154
|
+
async (args) => {
|
|
155
|
+
let content = await import_fs.promises.readFile(args.path, "utf-8");
|
|
156
|
+
if (!!alias) {
|
|
157
|
+
content = await aliasLessImports(content, alias, args.path);
|
|
158
|
+
}
|
|
159
|
+
const dir = import_path.default.dirname(args.path);
|
|
160
|
+
const filename = import_path.default.basename(args.path);
|
|
161
|
+
try {
|
|
162
|
+
const result = await import_less.default.render(content, {
|
|
163
|
+
plugins: [
|
|
164
|
+
new import_less_plugin_alias.default({
|
|
165
|
+
alias: alias || {}
|
|
166
|
+
})
|
|
167
|
+
],
|
|
168
|
+
filename,
|
|
169
|
+
rootpath: dir,
|
|
170
|
+
...lessOptions,
|
|
171
|
+
paths: [...lessOptions.paths || [], dir]
|
|
172
|
+
});
|
|
173
|
+
const postcssrResult = await (0, import_postcssProcess.postcssProcess)(
|
|
174
|
+
config,
|
|
175
|
+
result.css,
|
|
176
|
+
args.path
|
|
177
|
+
);
|
|
178
|
+
return {
|
|
179
|
+
contents: postcssrResult.css,
|
|
180
|
+
loader: inlineStyle ? "text" : "css",
|
|
181
|
+
resolveDir: dir
|
|
182
|
+
};
|
|
183
|
+
} catch (error) {
|
|
184
|
+
return {
|
|
185
|
+
errors: [
|
|
186
|
+
{
|
|
187
|
+
text: error.message,
|
|
188
|
+
location: {
|
|
189
|
+
namespace: "file",
|
|
190
|
+
file: error.filename,
|
|
191
|
+
line: error.line,
|
|
192
|
+
column: error.column
|
|
193
|
+
}
|
|
49
194
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
195
|
+
],
|
|
196
|
+
resolveDir: dir
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
53
203
|
};
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
aliasLessImportPath
|
|
207
|
+
});
|
|
@@ -1,14 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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/plugins/nodeGlobalsPolyfill.ts
|
|
20
|
+
var nodeGlobalsPolyfill_exports = {};
|
|
21
|
+
__export(nodeGlobalsPolyfill_exports, {
|
|
22
|
+
nodeGlobalsPolyfill: () => nodeGlobalsPolyfill
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(nodeGlobalsPolyfill_exports);
|
|
4
25
|
function nodeGlobalsPolyfill() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
26
|
+
return {
|
|
27
|
+
name: "node-globals-polyfill",
|
|
28
|
+
setup({ initialOptions, onResolve, onLoad }) {
|
|
29
|
+
onResolve;
|
|
30
|
+
onLoad;
|
|
31
|
+
initialOptions.inject || (initialOptions.inject = []);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
13
34
|
}
|
|
14
|
-
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
nodeGlobalsPolyfill
|
|
38
|
+
});
|
package/dist/plugins/style.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Charset, Plugin } from '@umijs/bundler-utils/compiled/esbuild';
|
|
2
|
+
import { IConfig } from '../types';
|
|
2
3
|
export interface StylePluginOptions {
|
|
3
4
|
/**
|
|
4
5
|
* whether to minify the css code.
|
|
@@ -10,5 +11,7 @@ export interface StylePluginOptions {
|
|
|
10
11
|
* @default 'utf8'
|
|
11
12
|
*/
|
|
12
13
|
charset?: Charset;
|
|
14
|
+
inlineStyle?: boolean;
|
|
15
|
+
config?: IConfig;
|
|
13
16
|
}
|
|
14
|
-
export declare function
|
|
17
|
+
export declare function style({ minify, charset, inlineStyle, config, }?: StylePluginOptions): Plugin;
|