@umijs/bundler-esbuild 4.0.0-beta.13 → 4.0.0-beta.14
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.js +8 -2
- package/dist/plugins/less.d.ts +2 -0
- package/dist/plugins/less.js +5 -2
- package/dist/plugins/style.d.ts +4 -1
- package/dist/plugins/style.js +86 -44
- package/dist/utils/getBrowserlist.d.ts +1 -0
- package/dist/utils/getBrowserlist.js +11 -0
- package/dist/utils/postcssProcess.d.ts +2 -0
- package/dist/utils/postcssProcess.js +33 -0
- package/package.json +8 -4
package/dist/build.js
CHANGED
|
@@ -38,16 +38,22 @@ function build(opts) {
|
|
|
38
38
|
plugins: [
|
|
39
39
|
(0, less_1.default)(Object.assign({ modifyVars: opts.config.theme, javascriptEnabled: true, alias: opts.config.alias,
|
|
40
40
|
// ref: https://github.com/umijs/umi-next/pull/214
|
|
41
|
-
inlineStyle: opts.inlineStyle }, opts.config.lessLoader)),
|
|
41
|
+
inlineStyle: opts.inlineStyle, config: opts.config }, opts.config.lessLoader)),
|
|
42
42
|
opts.config.alias && (0, alias_1.default)(addCwdPrefix(opts.config.alias, opts.cwd)),
|
|
43
43
|
opts.config.externals && (0, externals_1.default)(opts.config.externals),
|
|
44
|
-
|
|
44
|
+
(0, style_1.style)({
|
|
45
|
+
inlineStyle: opts.inlineStyle,
|
|
46
|
+
config: opts.config,
|
|
47
|
+
}),
|
|
45
48
|
].filter(Boolean),
|
|
46
49
|
define: {
|
|
47
50
|
// __dirname sham
|
|
48
51
|
__dirname: JSON.stringify('__dirname'),
|
|
49
52
|
'process.env.NODE_ENV': JSON.stringify(opts.mode || 'development'),
|
|
50
53
|
},
|
|
54
|
+
loader: {
|
|
55
|
+
'.svg': 'dataurl',
|
|
56
|
+
},
|
|
51
57
|
});
|
|
52
58
|
});
|
|
53
59
|
}
|
package/dist/plugins/less.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="less" />
|
|
2
2
|
import { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
|
|
3
|
+
import { IConfig } from '../types';
|
|
3
4
|
declare const _default: (options?: Less.Options & {
|
|
4
5
|
alias?: Record<string, string>;
|
|
5
6
|
inlineStyle?: boolean;
|
|
7
|
+
config?: IConfig;
|
|
6
8
|
}) => Plugin;
|
|
7
9
|
export default _default;
|
package/dist/plugins/less.js
CHANGED
|
@@ -28,6 +28,7 @@ const fs_1 = require("fs");
|
|
|
28
28
|
const less_1 = __importDefault(require("less"));
|
|
29
29
|
const less_plugin_aliases_1 = __importDefault(require("less-plugin-aliases"));
|
|
30
30
|
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const postcssProcess_1 = require("../utils/postcssProcess");
|
|
31
32
|
const sortByAffix_1 = require("../utils/sortByAffix");
|
|
32
33
|
const resolver = enhanced_resolve_1.default.create({
|
|
33
34
|
mainFields: ['module', 'browser', 'main'],
|
|
@@ -83,7 +84,7 @@ const aliasLessImportPath = (filePath, alias, importer) => __awaiter(void 0, voi
|
|
|
83
84
|
return null;
|
|
84
85
|
});
|
|
85
86
|
exports.default = (options = {}) => {
|
|
86
|
-
const { alias, inlineStyle } = options, lessOptions = __rest(options, ["alias", "inlineStyle"]);
|
|
87
|
+
const { alias, inlineStyle, config } = options, lessOptions = __rest(options, ["alias", "inlineStyle", "config"]);
|
|
87
88
|
return {
|
|
88
89
|
name: 'less',
|
|
89
90
|
setup({ onResolve, onLoad }) {
|
|
@@ -118,6 +119,7 @@ exports.default = (options = {}) => {
|
|
|
118
119
|
import { injectStyle } from "__style_helper__"
|
|
119
120
|
import css from ${JSON.stringify(args.path)}
|
|
120
121
|
injectStyle(css)
|
|
122
|
+
export default{}
|
|
121
123
|
`,
|
|
122
124
|
});
|
|
123
125
|
}));
|
|
@@ -136,8 +138,9 @@ exports.default = (options = {}) => {
|
|
|
136
138
|
aliases: alias || {},
|
|
137
139
|
}),
|
|
138
140
|
], filename, rootpath: dir }, lessOptions), { paths: [...(lessOptions.paths || []), dir] }));
|
|
141
|
+
const postcssrResult = yield (0, postcssProcess_1.postcssProcess)(config, result.css, args.path);
|
|
139
142
|
return {
|
|
140
|
-
contents:
|
|
143
|
+
contents: postcssrResult.css,
|
|
141
144
|
loader: inlineStyle ? 'text' : 'css',
|
|
142
145
|
resolveDir: dir,
|
|
143
146
|
};
|
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;
|
package/dist/plugins/style.js
CHANGED
|
@@ -12,13 +12,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.style = void 0;
|
|
16
16
|
// ref: https://github.com/hyrious/esbuild-plugin-style/blob/main/index.ts
|
|
17
17
|
const esbuild_1 = __importDefault(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
18
|
+
const utils_1 = require("@umijs/utils");
|
|
18
19
|
const fs_1 = __importDefault(require("fs"));
|
|
19
20
|
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const postcssProcess_1 = require("../utils/postcssProcess");
|
|
20
22
|
// https://github.com/evanw/esbuild/issues/20#issuecomment-802269745
|
|
21
|
-
function
|
|
23
|
+
function style({ minify = true, charset = 'utf8', inlineStyle, config, } = {}) {
|
|
22
24
|
return {
|
|
23
25
|
name: 'style',
|
|
24
26
|
setup({ onResolve, onLoad }) {
|
|
@@ -29,55 +31,95 @@ function inlineStyle({ minify = true, charset = 'utf8', } = {}) {
|
|
|
29
31
|
write: false,
|
|
30
32
|
charset,
|
|
31
33
|
minify,
|
|
34
|
+
loader: {
|
|
35
|
+
'.svg': 'dataurl',
|
|
36
|
+
},
|
|
32
37
|
};
|
|
33
38
|
onResolve({ filter: /\.css$/, namespace: 'file' }, (args) => {
|
|
34
|
-
const absPath = path_1.default.
|
|
35
|
-
|
|
36
|
-
const resolved = fs_1.default.existsSync(absPath)
|
|
37
|
-
|
|
39
|
+
const absPath = path_1.default.resolve(cwd, path_1.default.relative(cwd, args.resolveDir), args.path);
|
|
40
|
+
// 通过 resolve 往上找,依赖不一定在 node_modules,可能被提到根目录,并且没有 link
|
|
41
|
+
const resolved = fs_1.default.existsSync(absPath)
|
|
42
|
+
? absPath
|
|
43
|
+
: utils_1.resolve.sync(`${args.path}`, {
|
|
44
|
+
basedir: args.resolveDir,
|
|
45
|
+
});
|
|
46
|
+
return { path: resolved, namespace: inlineStyle ? 'style-stub' : '' };
|
|
38
47
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
onResolve({ filter: /^__style_helper__$/, namespace: 'style-stub' }, (args) => ({
|
|
43
|
-
path: args.path,
|
|
44
|
-
namespace: 'style-helper',
|
|
45
|
-
sideEffects: false,
|
|
46
|
-
}));
|
|
47
|
-
onLoad({ filter: /.*/, namespace: 'style-helper' }, () => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
return ({
|
|
49
|
-
contents: `
|
|
50
|
-
export function injectStyle(text) {
|
|
51
|
-
if (typeof document !== 'undefined') {
|
|
52
|
-
var style = document.createElement('style')
|
|
53
|
-
var node = document.createTextNode(text)
|
|
54
|
-
style.appendChild(node)
|
|
55
|
-
document.head.appendChild(style)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
`,
|
|
59
|
-
});
|
|
60
|
-
}));
|
|
61
|
-
onLoad({ filter: /.*/, namespace: 'style-stub' }, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
return ({
|
|
63
|
-
contents: `
|
|
64
|
-
import { injectStyle } from "__style_helper__"
|
|
65
|
-
import css from ${JSON.stringify(args.path)}
|
|
66
|
-
injectStyle(css)
|
|
67
|
-
`,
|
|
48
|
+
if (inlineStyle) {
|
|
49
|
+
onResolve({ filter: /\.css$/, namespace: 'style-stub' }, (args) => {
|
|
50
|
+
return { path: args.path, namespace: 'style-content' };
|
|
68
51
|
});
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
onResolve({ filter: /^__style_helper__$/, namespace: 'style-stub' }, (args) => ({
|
|
53
|
+
path: args.path,
|
|
54
|
+
namespace: 'style-helper',
|
|
55
|
+
sideEffects: false,
|
|
56
|
+
}));
|
|
57
|
+
onLoad({ filter: /.*/, namespace: 'style-helper' }, () => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return ({
|
|
59
|
+
contents: `
|
|
60
|
+
export function injectStyle(text) {
|
|
61
|
+
if (typeof document !== 'undefined') {
|
|
62
|
+
var style = document.createElement('style')
|
|
63
|
+
var node = document.createTextNode(text)
|
|
64
|
+
style.appendChild(node)
|
|
65
|
+
document.head.appendChild(style)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`,
|
|
69
|
+
});
|
|
70
|
+
}));
|
|
71
|
+
onLoad({ filter: /.*/, namespace: 'style-stub' }, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return ({
|
|
73
|
+
contents: `
|
|
74
|
+
import { injectStyle } from "__style_helper__"
|
|
75
|
+
import css from ${JSON.stringify(args.path)}
|
|
76
|
+
injectStyle(css)
|
|
77
|
+
`,
|
|
78
|
+
});
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
onLoad({
|
|
82
|
+
filter: inlineStyle ? /.*/ : /\.css$/,
|
|
83
|
+
namespace: inlineStyle ? 'style-content' : 'file',
|
|
84
|
+
}, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
71
85
|
const options = Object.assign({ entryPoints: [args.path] }, opt);
|
|
72
86
|
const { errors, warnings, outputFiles } = yield esbuild_1.default.build(options);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
87
|
+
if (errors.length > 0) {
|
|
88
|
+
return {
|
|
89
|
+
errors,
|
|
90
|
+
warnings,
|
|
91
|
+
contents: outputFiles[0].text,
|
|
92
|
+
loader: 'text',
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const dir = path_1.default.dirname(args.path);
|
|
96
|
+
try {
|
|
97
|
+
const result = yield (0, postcssProcess_1.postcssProcess)(config, outputFiles[0].text, args.path);
|
|
98
|
+
return {
|
|
99
|
+
errors,
|
|
100
|
+
warnings,
|
|
101
|
+
contents: result.css,
|
|
102
|
+
loader: inlineStyle ? 'text' : 'css',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
return {
|
|
107
|
+
errors: [
|
|
108
|
+
{
|
|
109
|
+
text: error.message,
|
|
110
|
+
location: {
|
|
111
|
+
namespace: 'file',
|
|
112
|
+
file: error.filename,
|
|
113
|
+
line: error.line,
|
|
114
|
+
column: error.column,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
resolveDir: dir,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
79
121
|
}));
|
|
80
122
|
},
|
|
81
123
|
};
|
|
82
124
|
}
|
|
83
|
-
exports.
|
|
125
|
+
exports.style = style;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getBrowserlist(targets: Record<string, string | boolean>): string | true | string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrowserlist = void 0;
|
|
4
|
+
// refer: https://github.com/umijs/umi-next/blob/867e0c196296efbbdb95203cca35db2fa639808b/packages/bundler-webpack/src/utils/browsersList.ts#L5
|
|
5
|
+
function getBrowserlist(targets) {
|
|
6
|
+
return (targets.browsers ||
|
|
7
|
+
Object.keys(targets).map((key) => {
|
|
8
|
+
return `${key} >= ${targets[key] === true ? '0' : targets[key]}`;
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
exports.getBrowserlist = getBrowserlist;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.postcssProcess = void 0;
|
|
16
|
+
const postcss_1 = __importDefault(require("postcss"));
|
|
17
|
+
const getBrowserlist_1 = require("./getBrowserlist");
|
|
18
|
+
function postcssProcess(config, css, path) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return yield (0, postcss_1.default)([
|
|
21
|
+
require('postcss-flexbugs-fixes'),
|
|
22
|
+
require('postcss-preset-env')({
|
|
23
|
+
browsers: (0, getBrowserlist_1.getBrowserlist)((config === null || config === void 0 ? void 0 : config.targets) || {}),
|
|
24
|
+
autoprefixer: Object.assign({ flexbox: 'no-2009' }, config === null || config === void 0 ? void 0 : config.autoprefixer),
|
|
25
|
+
stage: 3,
|
|
26
|
+
}),
|
|
27
|
+
].concat((config === null || config === void 0 ? void 0 : config.extraPostCSSPlugins) || [])).process(css, {
|
|
28
|
+
from: path,
|
|
29
|
+
to: path,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.postcssProcess = postcssProcess;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-esbuild",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.14",
|
|
4
4
|
"description": "@umijs/bundler-esbuild",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-esbuild#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -23,13 +23,17 @@
|
|
|
23
23
|
"dev": "pnpm build -- --watch"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@umijs/bundler-utils": "4.0.0-beta.
|
|
27
|
-
"@umijs/utils": "4.0.0-beta.
|
|
26
|
+
"@umijs/bundler-utils": "4.0.0-beta.14",
|
|
27
|
+
"@umijs/utils": "4.0.0-beta.14",
|
|
28
28
|
"enhanced-resolve": "5.8.3",
|
|
29
29
|
"less": "4.1.2",
|
|
30
|
-
"less-plugin-aliases": "^1.0.3"
|
|
30
|
+
"less-plugin-aliases": "^1.0.3",
|
|
31
|
+
"postcss": "^8.4.4",
|
|
32
|
+
"postcss-flexbugs-fixes": "5.0.2",
|
|
33
|
+
"postcss-preset-env": "7.0.1"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
36
|
+
"@alitajs/postcss-plugin-px2rem": "^0.0.1",
|
|
33
37
|
"@types/less": "^3.0.3"
|
|
34
38
|
},
|
|
35
39
|
"publishConfig": {
|