@winner-fed/bundler-esbuild 0.8.13-alpha.0
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/README.md +3 -0
- package/bin/bundler-esbuild.js +2 -0
- package/dist/build.d.ts +19 -0
- package/dist/build.js +102 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +74 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -0
- package/dist/plugins/__sample.d.ts +2 -0
- package/dist/plugins/__sample.js +32 -0
- package/dist/plugins/alias.d.ts +3 -0
- package/dist/plugins/alias.js +96 -0
- package/dist/plugins/externals.d.ts +3 -0
- package/dist/plugins/externals.js +44 -0
- 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 +9 -0
- package/dist/plugins/less.js +207 -0
- package/dist/plugins/nodeGlobalsPolyfill.d.ts +2 -0
- package/dist/plugins/nodeGlobalsPolyfill.js +38 -0
- package/dist/plugins/style.d.ts +17 -0
- package/dist/plugins/style.js +171 -0
- package/dist/plugins/watchRebuild.d.ts +4 -0
- package/dist/plugins/watchRebuild.js +67 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.js +40 -0
- package/dist/utils/getBrowserlist.d.ts +1 -0
- package/dist/utils/getBrowserlist.js +33 -0
- package/dist/utils/postcssProcess.d.ts +3 -0
- package/dist/utils/postcssProcess.js +58 -0
- package/dist/utils/sortByAffix.d.ts +4 -0
- package/dist/utils/sortByAffix.js +40 -0
- package/package.json +33 -0
package/README.md
ADDED
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BuildOptions, Format } from '@winner-fed/bundler-utils/compiled/esbuild';
|
|
2
|
+
import { IBabelPlugin, IConfig } from './types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
cwd: string;
|
|
5
|
+
entry: Record<string, string>;
|
|
6
|
+
config: IConfig;
|
|
7
|
+
mode?: string;
|
|
8
|
+
onBuildComplete?: Function;
|
|
9
|
+
clean?: boolean;
|
|
10
|
+
format?: Format;
|
|
11
|
+
sourcemap?: boolean | 'inline' | 'external' | 'both';
|
|
12
|
+
beforeBabelPlugins?: any[];
|
|
13
|
+
beforeBabelPresets?: any[];
|
|
14
|
+
extraBabelPlugins?: IBabelPlugin[];
|
|
15
|
+
extraBabelPresets?: IBabelPlugin[];
|
|
16
|
+
inlineStyle?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function build(opts: IOpts): Promise<import("@winner-fed/bundler-utils/compiled/esbuild").BuildResult<BuildOptions>>;
|
|
19
|
+
export {};
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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_esbuild = require("@winner-fed/bundler-utils/compiled/esbuild");
|
|
36
|
+
var import_utils = require("@winner-fed/utils");
|
|
37
|
+
var import_path = require("path");
|
|
38
|
+
var import_alias = __toESM(require("./plugins/alias"));
|
|
39
|
+
var import_externals = __toESM(require("./plugins/externals"));
|
|
40
|
+
var import_less = __toESM(require("./plugins/less"));
|
|
41
|
+
var import_style = require("./plugins/style");
|
|
42
|
+
async function build(opts) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const outputPath = opts.config.outputPath || (0, import_path.join)(opts.cwd, "dist");
|
|
45
|
+
if (opts.clean) {
|
|
46
|
+
import_utils.rimraf.sync(outputPath);
|
|
47
|
+
}
|
|
48
|
+
const config = {
|
|
49
|
+
entryPoints: opts.entry,
|
|
50
|
+
bundle: true,
|
|
51
|
+
format: opts.format || "iife",
|
|
52
|
+
logLevel: "error",
|
|
53
|
+
// splitting: true,
|
|
54
|
+
sourcemap: opts.sourcemap,
|
|
55
|
+
outdir: outputPath,
|
|
56
|
+
metafile: true,
|
|
57
|
+
plugins: [
|
|
58
|
+
(0, import_less.default)({
|
|
59
|
+
modifyVars: opts.config.theme,
|
|
60
|
+
javascriptEnabled: true,
|
|
61
|
+
alias: opts.config.alias,
|
|
62
|
+
// ref: https://github.com/umijs/umi-next/pull/214
|
|
63
|
+
inlineStyle: opts.inlineStyle,
|
|
64
|
+
config: opts.config,
|
|
65
|
+
...opts.config.lessLoader
|
|
66
|
+
}),
|
|
67
|
+
opts.config.alias && (0, import_alias.default)(addCwdPrefix(opts.config.alias, opts.cwd)),
|
|
68
|
+
opts.config.externals && (0, import_externals.default)(opts.config.externals),
|
|
69
|
+
(0, import_style.style)({
|
|
70
|
+
inlineStyle: opts.inlineStyle,
|
|
71
|
+
config: opts.config
|
|
72
|
+
})
|
|
73
|
+
].filter(Boolean),
|
|
74
|
+
define: {
|
|
75
|
+
// __dirname sham
|
|
76
|
+
__dirname: JSON.stringify("__dirname"),
|
|
77
|
+
"process.env.NODE_ENV": JSON.stringify(opts.mode || "development"),
|
|
78
|
+
...opts.config.define
|
|
79
|
+
},
|
|
80
|
+
loader: {
|
|
81
|
+
".svg": "dataurl",
|
|
82
|
+
".ttf": "dataurl",
|
|
83
|
+
".wasm": "dataurl",
|
|
84
|
+
...opts.config.loader
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
await ((_b = (_a = opts.config).modifyConfig) == null ? void 0 : _b.call(_a, config));
|
|
88
|
+
const result = await (0, import_esbuild.build)(config);
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
function addCwdPrefix(obj, cwd) {
|
|
92
|
+
Object.keys(obj).forEach((key) => {
|
|
93
|
+
if (obj[key].startsWith(".")) {
|
|
94
|
+
obj[key] = (0, import_utils.winPath)((0, import_path.join)(cwd, obj[key]));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return obj;
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
build
|
|
102
|
+
});
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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("@winner-fed/bundler-utils/compiled/esbuild"));
|
|
26
|
+
var import_utils = require("@winner-fed/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 args = (0, import_utils.yParser)(process.argv.slice(2), {});
|
|
32
|
+
var command = args._[0];
|
|
33
|
+
var cwd = process.cwd();
|
|
34
|
+
var entry = (0, import_utils.tryPaths)([
|
|
35
|
+
(0, import_path.join)(cwd, "src/index.tsx"),
|
|
36
|
+
(0, import_path.join)(cwd, "src/index.ts"),
|
|
37
|
+
(0, import_path.join)(cwd, "index.tsx"),
|
|
38
|
+
(0, import_path.join)(cwd, "index.ts")
|
|
39
|
+
]);
|
|
40
|
+
var config = {};
|
|
41
|
+
var configFile = (0, import_path.join)(cwd, args.config || "config.ts");
|
|
42
|
+
import_utils.register.register({
|
|
43
|
+
implementor: import_esbuild.default
|
|
44
|
+
});
|
|
45
|
+
import_utils.register.clearFiles();
|
|
46
|
+
if ((0, import_fs.existsSync)(configFile)) {
|
|
47
|
+
config = require(configFile).default;
|
|
48
|
+
}
|
|
49
|
+
Object.assign(config, args);
|
|
50
|
+
if (command === "build") {
|
|
51
|
+
(async () => {
|
|
52
|
+
process.env.NODE_ENV = "production";
|
|
53
|
+
(0, import_assert.default)(entry, `Build failed: entry not found.`);
|
|
54
|
+
try {
|
|
55
|
+
await (0, import_build.build)({
|
|
56
|
+
config,
|
|
57
|
+
cwd,
|
|
58
|
+
entry: {
|
|
59
|
+
[getEntryKey(entry)]: entry
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(e);
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
} else {
|
|
67
|
+
error(`Unsupported command ${command}.`);
|
|
68
|
+
}
|
|
69
|
+
function error(msg) {
|
|
70
|
+
console.error(import_utils.chalk.red(msg));
|
|
71
|
+
}
|
|
72
|
+
function getEntryKey(path) {
|
|
73
|
+
return (0, import_path.basename)(path, (0, import_path.extname)(path));
|
|
74
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './build';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
var src_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(src_exports);
|
|
19
|
+
__reExport(src_exports, require("./build"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./build")
|
|
23
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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/__sample.ts
|
|
20
|
+
var sample_exports = {};
|
|
21
|
+
__export(sample_exports, {
|
|
22
|
+
Sample: () => Sample
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(sample_exports);
|
|
25
|
+
function Sample() {
|
|
26
|
+
return { name: "", setup() {
|
|
27
|
+
} };
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
Sample
|
|
32
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
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/plugins/alias.ts
|
|
30
|
+
var alias_exports = {};
|
|
31
|
+
__export(alias_exports, {
|
|
32
|
+
default: () => alias_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(alias_exports);
|
|
35
|
+
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
36
|
+
var import_fs = require("fs");
|
|
37
|
+
var import_sortByAffix = require("../utils/sortByAffix");
|
|
38
|
+
var resolver = import_enhanced_resolve.default.create({
|
|
39
|
+
mainFields: ["module", "browser", "main"],
|
|
40
|
+
extensions: [".json", ".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"],
|
|
41
|
+
// TODO: support exports
|
|
42
|
+
exportsFields: []
|
|
43
|
+
});
|
|
44
|
+
async function resolve(context, path) {
|
|
45
|
+
return new Promise((resolve2, reject) => {
|
|
46
|
+
resolver(
|
|
47
|
+
context,
|
|
48
|
+
path,
|
|
49
|
+
(err, result) => err ? reject(err) : resolve2(result)
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
var alias_default = (options = {}) => {
|
|
54
|
+
return {
|
|
55
|
+
name: "alias",
|
|
56
|
+
setup({ onResolve }) {
|
|
57
|
+
const keys = (0, import_sortByAffix.sortByAffix)({ arr: Object.keys(options), affix: "$" });
|
|
58
|
+
keys.forEach((key) => {
|
|
59
|
+
let value = options[key];
|
|
60
|
+
let filter;
|
|
61
|
+
if (key.endsWith("$")) {
|
|
62
|
+
filter = new RegExp(`^${key}`);
|
|
63
|
+
} else {
|
|
64
|
+
filter = new RegExp(`^${key}$`);
|
|
65
|
+
}
|
|
66
|
+
onResolve({ filter }, async (args) => {
|
|
67
|
+
const path = await resolve(
|
|
68
|
+
args.importer,
|
|
69
|
+
args.path.replace(filter, value)
|
|
70
|
+
);
|
|
71
|
+
return {
|
|
72
|
+
path
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
if (!key.endsWith("/") && (0, import_fs.existsSync)(value) && (0, import_fs.statSync)(value).isDirectory()) {
|
|
76
|
+
const filter2 = new RegExp(`^${addSlashAffix(key)}`);
|
|
77
|
+
onResolve({ filter: filter2 }, async (args) => {
|
|
78
|
+
const path = await resolve(
|
|
79
|
+
args.importer,
|
|
80
|
+
args.path.replace(filter2, addSlashAffix(value))
|
|
81
|
+
);
|
|
82
|
+
return {
|
|
83
|
+
path
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
function addSlashAffix(key) {
|
|
92
|
+
if (key.endsWith("/")) {
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
return `${key}/`;
|
|
96
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
};
|
|
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("@winner-fed/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
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Plugin } from '@winner-fed/bundler-utils/compiled/esbuild';
|
|
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;
|
|
9
|
+
export default _default;
|