@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
|
@@ -0,0 +1,207 @@
|
|
|
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/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("@winner-fed/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
|
+
}
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
resolveDir: dir
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
aliasLessImportPath
|
|
207
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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);
|
|
25
|
+
function nodeGlobalsPolyfill() {
|
|
26
|
+
return {
|
|
27
|
+
name: "node-globals-polyfill",
|
|
28
|
+
setup({ initialOptions, onResolve, onLoad }) {
|
|
29
|
+
onResolve;
|
|
30
|
+
onLoad;
|
|
31
|
+
initialOptions.inject || (initialOptions.inject = []);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
nodeGlobalsPolyfill
|
|
38
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Charset, Plugin } from '@winner-fed/bundler-utils/compiled/esbuild';
|
|
2
|
+
import { IConfig } from '../types';
|
|
3
|
+
export interface StylePluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* whether to minify the css code.
|
|
6
|
+
* @default true
|
|
7
|
+
*/
|
|
8
|
+
minify?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* css charset.
|
|
11
|
+
* @default 'utf8'
|
|
12
|
+
*/
|
|
13
|
+
charset?: Charset;
|
|
14
|
+
inlineStyle?: boolean;
|
|
15
|
+
config?: IConfig;
|
|
16
|
+
}
|
|
17
|
+
export declare function style({ minify, charset, inlineStyle, config, }?: StylePluginOptions): Plugin;
|
|
@@ -0,0 +1,171 @@
|
|
|
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/style.ts
|
|
30
|
+
var style_exports = {};
|
|
31
|
+
__export(style_exports, {
|
|
32
|
+
style: () => style
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(style_exports);
|
|
35
|
+
var import_esbuild = __toESM(require("@winner-fed/bundler-utils/compiled/esbuild"));
|
|
36
|
+
var import_utils = require("@winner-fed/utils");
|
|
37
|
+
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_postcssProcess = require("../utils/postcssProcess");
|
|
40
|
+
function style({
|
|
41
|
+
minify = true,
|
|
42
|
+
charset = "utf8",
|
|
43
|
+
inlineStyle,
|
|
44
|
+
config
|
|
45
|
+
} = {}) {
|
|
46
|
+
return {
|
|
47
|
+
name: "style",
|
|
48
|
+
setup({ onResolve, onLoad }) {
|
|
49
|
+
const cwd = process.cwd();
|
|
50
|
+
const opt = {
|
|
51
|
+
logLevel: "silent",
|
|
52
|
+
bundle: true,
|
|
53
|
+
write: false,
|
|
54
|
+
charset,
|
|
55
|
+
minify,
|
|
56
|
+
loader: {
|
|
57
|
+
// images
|
|
58
|
+
".svg": "dataurl",
|
|
59
|
+
".png": "dataurl",
|
|
60
|
+
".jpg": "dataurl",
|
|
61
|
+
".jpeg": "dataurl",
|
|
62
|
+
".gif": "dataurl",
|
|
63
|
+
".ico": "dataurl",
|
|
64
|
+
".webp": "dataurl",
|
|
65
|
+
// font
|
|
66
|
+
".ttf": "dataurl",
|
|
67
|
+
".otf": "dataurl",
|
|
68
|
+
".woff": "dataurl",
|
|
69
|
+
".woff2": "dataurl",
|
|
70
|
+
".eot": "dataurl"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
onResolve({ filter: /\.css$/, namespace: "file" }, (args) => {
|
|
74
|
+
const absPath = import_path.default.resolve(
|
|
75
|
+
cwd,
|
|
76
|
+
import_path.default.relative(cwd, args.resolveDir),
|
|
77
|
+
args.path
|
|
78
|
+
);
|
|
79
|
+
const resolved = import_fs.default.existsSync(absPath) ? absPath : import_utils.resolve.sync(`${args.path}`, {
|
|
80
|
+
basedir: args.resolveDir
|
|
81
|
+
});
|
|
82
|
+
return { path: resolved, namespace: inlineStyle ? "style-stub" : "" };
|
|
83
|
+
});
|
|
84
|
+
if (inlineStyle) {
|
|
85
|
+
onResolve({ filter: /\.css$/, namespace: "style-stub" }, (args) => {
|
|
86
|
+
return { path: args.path, namespace: "style-content" };
|
|
87
|
+
});
|
|
88
|
+
onResolve(
|
|
89
|
+
{ filter: /^__style_helper__$/, namespace: "style-stub" },
|
|
90
|
+
(args) => ({
|
|
91
|
+
path: args.path,
|
|
92
|
+
namespace: "style-helper",
|
|
93
|
+
sideEffects: false
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
onLoad({ filter: /.*/, namespace: "style-helper" }, async () => ({
|
|
97
|
+
contents: `
|
|
98
|
+
export function injectStyle(text) {
|
|
99
|
+
if (typeof document !== 'undefined') {
|
|
100
|
+
var style = document.createElement('style')
|
|
101
|
+
var node = document.createTextNode(text)
|
|
102
|
+
style.appendChild(node)
|
|
103
|
+
document.head.appendChild(style)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`
|
|
107
|
+
}));
|
|
108
|
+
onLoad({ filter: /.*/, namespace: "style-stub" }, async (args) => ({
|
|
109
|
+
contents: `
|
|
110
|
+
import { injectStyle } from "__style_helper__"
|
|
111
|
+
import css from ${JSON.stringify(args.path)}
|
|
112
|
+
injectStyle(css)
|
|
113
|
+
`
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
onLoad(
|
|
117
|
+
{
|
|
118
|
+
filter: inlineStyle ? /.*/ : /\.css$/,
|
|
119
|
+
namespace: inlineStyle ? "style-content" : "file"
|
|
120
|
+
},
|
|
121
|
+
async (args) => {
|
|
122
|
+
const options = { entryPoints: [args.path], ...opt };
|
|
123
|
+
const { errors, warnings, outputFiles } = await import_esbuild.default.build(
|
|
124
|
+
options
|
|
125
|
+
);
|
|
126
|
+
if (errors.length > 0) {
|
|
127
|
+
return {
|
|
128
|
+
errors,
|
|
129
|
+
warnings,
|
|
130
|
+
contents: outputFiles[0].text,
|
|
131
|
+
loader: "text"
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const dir = import_path.default.dirname(args.path);
|
|
135
|
+
try {
|
|
136
|
+
const result = await (0, import_postcssProcess.postcssProcess)(
|
|
137
|
+
config,
|
|
138
|
+
outputFiles[0].text,
|
|
139
|
+
args.path
|
|
140
|
+
);
|
|
141
|
+
return {
|
|
142
|
+
errors,
|
|
143
|
+
warnings,
|
|
144
|
+
contents: result.css,
|
|
145
|
+
loader: inlineStyle ? "text" : "css"
|
|
146
|
+
};
|
|
147
|
+
} catch (error) {
|
|
148
|
+
return {
|
|
149
|
+
errors: [
|
|
150
|
+
{
|
|
151
|
+
text: error.message,
|
|
152
|
+
location: {
|
|
153
|
+
namespace: "file",
|
|
154
|
+
file: error.filename,
|
|
155
|
+
line: error.line,
|
|
156
|
+
column: error.column
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
resolveDir: dir
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
169
|
+
0 && (module.exports = {
|
|
170
|
+
style
|
|
171
|
+
});
|
|
@@ -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/plugins/watchRebuild.ts
|
|
20
|
+
var watchRebuild_exports = {};
|
|
21
|
+
__export(watchRebuild_exports, {
|
|
22
|
+
esbuildWatchRebuildPlugin: () => esbuildWatchRebuildPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(watchRebuild_exports);
|
|
25
|
+
function failureErrorWithLog(text, errors, warnings) {
|
|
26
|
+
let limit = 5;
|
|
27
|
+
let summary = errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e, i) => {
|
|
28
|
+
if (i === limit)
|
|
29
|
+
return "\n...";
|
|
30
|
+
if (!e.location)
|
|
31
|
+
return `
|
|
32
|
+
error: ${e.text}`;
|
|
33
|
+
let { file, line, column } = e.location;
|
|
34
|
+
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
|
35
|
+
return `
|
|
36
|
+
${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
|
|
37
|
+
}).join("");
|
|
38
|
+
let error = new Error(`${text}${summary}`);
|
|
39
|
+
error.errors = errors;
|
|
40
|
+
error.warnings = warnings;
|
|
41
|
+
return error;
|
|
42
|
+
}
|
|
43
|
+
function esbuildWatchRebuildPlugin(options) {
|
|
44
|
+
return {
|
|
45
|
+
name: "watch-rebuild-plugin",
|
|
46
|
+
setup(build) {
|
|
47
|
+
let count = 0;
|
|
48
|
+
build.onEnd((result) => {
|
|
49
|
+
if (count++ === 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (result.errors.length > 0) {
|
|
53
|
+
options.onRebuild(
|
|
54
|
+
failureErrorWithLog("Build failed", result.errors, result.warnings),
|
|
55
|
+
null
|
|
56
|
+
);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
options.onRebuild(null, result);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
esbuildWatchRebuildPlugin
|
|
67
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BuildOptions } from '@winner-fed/bundler-utils/compiled/esbuild';
|
|
2
|
+
import type { Plugin } from '@winner-fed/bundler-vite/compiled/vite';
|
|
3
|
+
export declare enum Env {
|
|
4
|
+
development = "development",
|
|
5
|
+
production = "production"
|
|
6
|
+
}
|
|
7
|
+
export declare enum JSMinifier {
|
|
8
|
+
terser = "terser",
|
|
9
|
+
esbuild = "esbuild"
|
|
10
|
+
}
|
|
11
|
+
export interface ICopy {
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
}
|
|
15
|
+
export type IBabelPlugin = Function | string | [string, {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}] | [string, {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}, string];
|
|
20
|
+
export interface IConfig {
|
|
21
|
+
alias?: Record<string, string>;
|
|
22
|
+
autoCSSModules?: boolean;
|
|
23
|
+
autoprefixer?: any;
|
|
24
|
+
copy?: ICopy[] | string[];
|
|
25
|
+
define?: {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
extraBabelPlugins?: IBabelPlugin[];
|
|
29
|
+
extraBabelPresets?: IBabelPlugin[];
|
|
30
|
+
extraPostCSSPlugins?: any[];
|
|
31
|
+
extraVitePlugins?: Plugin[];
|
|
32
|
+
hash?: boolean;
|
|
33
|
+
inlineLimit?: number;
|
|
34
|
+
manifest?: boolean;
|
|
35
|
+
normalCSSLoaderModules?: {
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
};
|
|
38
|
+
jsMinifier?: JSMinifier | boolean;
|
|
39
|
+
jsMinifierOptions?: {
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
};
|
|
42
|
+
lessLoader?: {
|
|
43
|
+
lessOptions: any;
|
|
44
|
+
};
|
|
45
|
+
outputPath?: string;
|
|
46
|
+
polyfill?: {
|
|
47
|
+
imports: string[];
|
|
48
|
+
};
|
|
49
|
+
postcssLoader?: {
|
|
50
|
+
postcssOptions: any;
|
|
51
|
+
};
|
|
52
|
+
publicPath?: string;
|
|
53
|
+
targets?: {
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
};
|
|
56
|
+
loader?: BuildOptions['loader'];
|
|
57
|
+
modifyConfig?: (config: BuildOptions) => void | Promise<void>;
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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/types.ts
|
|
20
|
+
var types_exports = {};
|
|
21
|
+
__export(types_exports, {
|
|
22
|
+
Env: () => Env,
|
|
23
|
+
JSMinifier: () => JSMinifier
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(types_exports);
|
|
26
|
+
var Env = /* @__PURE__ */ ((Env2) => {
|
|
27
|
+
Env2["development"] = "development";
|
|
28
|
+
Env2["production"] = "production";
|
|
29
|
+
return Env2;
|
|
30
|
+
})(Env || {});
|
|
31
|
+
var JSMinifier = /* @__PURE__ */ ((JSMinifier2) => {
|
|
32
|
+
JSMinifier2["terser"] = "terser";
|
|
33
|
+
JSMinifier2["esbuild"] = "esbuild";
|
|
34
|
+
return JSMinifier2;
|
|
35
|
+
})(JSMinifier || {});
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
Env,
|
|
39
|
+
JSMinifier
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getBrowserlist(targets: Record<string, string | boolean>): string | true | string[];
|
|
@@ -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/utils/getBrowserlist.ts
|
|
20
|
+
var getBrowserlist_exports = {};
|
|
21
|
+
__export(getBrowserlist_exports, {
|
|
22
|
+
getBrowserlist: () => getBrowserlist
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(getBrowserlist_exports);
|
|
25
|
+
function getBrowserlist(targets) {
|
|
26
|
+
return targets.browsers || Object.keys(targets).map((key) => {
|
|
27
|
+
return `${key} >= ${targets[key] === true ? "0" : targets[key]}`;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
getBrowserlist
|
|
33
|
+
});
|