@ohos-ports/parcel-optimizer-css 2.16.4-beta.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/LICENSE +21 -0
- package/lib/CSSOptimizer.js +233 -0
- package/package.json +39 -0
- package/src/CSSOptimizer.js +219 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present Devon Govett
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _sourceMap() {
|
|
8
|
+
const data = _interopRequireDefault(require("@ohos-ports/parcel-source-map"));
|
|
9
|
+
_sourceMap = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _plugin() {
|
|
15
|
+
const data = require("@parcel/plugin");
|
|
16
|
+
_plugin = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _lightningcss() {
|
|
22
|
+
const data = _interopRequireWildcard(require("@ohos-ports/lightningcss"));
|
|
23
|
+
_lightningcss = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _utils() {
|
|
29
|
+
const data = require("@ohos-ports/parcel-utils");
|
|
30
|
+
_utils = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _browserslist() {
|
|
36
|
+
const data = _interopRequireDefault(require("browserslist"));
|
|
37
|
+
_browserslist = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _nullthrows() {
|
|
43
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
44
|
+
_nullthrows = function () {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
function _path() {
|
|
50
|
+
const data = _interopRequireDefault(require("path"));
|
|
51
|
+
_path = function () {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
function _diagnostic() {
|
|
57
|
+
const data = require("@parcel/diagnostic");
|
|
58
|
+
_diagnostic = function () {
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
64
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
65
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
66
|
+
// $FlowFixMe - init for browser build.
|
|
67
|
+
var _default = exports.default = new (_plugin().Optimizer)({
|
|
68
|
+
async loadConfig({
|
|
69
|
+
config,
|
|
70
|
+
logger,
|
|
71
|
+
options
|
|
72
|
+
}) {
|
|
73
|
+
const configFile = await config.getConfig(['.cssnanorc', 'cssnano.config.json', 'cssnano.config.js', 'cssnano.config.cjs'], {
|
|
74
|
+
packageKey: 'cssnano'
|
|
75
|
+
});
|
|
76
|
+
if (configFile) {
|
|
77
|
+
let filename = _path().default.basename(configFile.filePath);
|
|
78
|
+
let codeHighlights;
|
|
79
|
+
let message;
|
|
80
|
+
if (filename === 'package.json') {
|
|
81
|
+
message = (0, _diagnostic().md)`
|
|
82
|
+
Parcel\'s default CSS minifer changed from cssnano to lightningcss, but a "cssnano" key was found in **package.json**. Either remove this configuration, or configure Parcel to use @parcel/optimizer-cssnano instead.
|
|
83
|
+
`;
|
|
84
|
+
let contents = await options.inputFS.readFile(configFile.filePath, 'utf8');
|
|
85
|
+
codeHighlights = (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
86
|
+
key: '/cssnano',
|
|
87
|
+
type: 'key'
|
|
88
|
+
}]);
|
|
89
|
+
} else {
|
|
90
|
+
message = (0, _diagnostic().md)`Parcel\'s default CSS minifer changed from cssnano to lightningcss, but a __${filename}__ config file was found. Either remove this config file, or configure Parcel to use @parcel/optimizer-cssnano instead.`;
|
|
91
|
+
codeHighlights = [{
|
|
92
|
+
start: {
|
|
93
|
+
line: 1,
|
|
94
|
+
column: 1
|
|
95
|
+
},
|
|
96
|
+
end: {
|
|
97
|
+
line: 1,
|
|
98
|
+
column: 1
|
|
99
|
+
}
|
|
100
|
+
}];
|
|
101
|
+
}
|
|
102
|
+
logger.warn({
|
|
103
|
+
message,
|
|
104
|
+
documentationURL: 'https://parceljs.org/languages/css/#minification',
|
|
105
|
+
codeFrames: [{
|
|
106
|
+
filePath: configFile.filePath,
|
|
107
|
+
codeHighlights
|
|
108
|
+
}]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
async optimize({
|
|
113
|
+
bundle,
|
|
114
|
+
bundleGraph,
|
|
115
|
+
logger,
|
|
116
|
+
contents: prevContents,
|
|
117
|
+
getSourceMapReference,
|
|
118
|
+
map: prevMap,
|
|
119
|
+
options
|
|
120
|
+
}) {
|
|
121
|
+
if (!bundle.env.shouldOptimize) {
|
|
122
|
+
return {
|
|
123
|
+
contents: prevContents,
|
|
124
|
+
map: prevMap
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
let targets = getTargets(bundle.env.engines.browsers);
|
|
128
|
+
let code = await (0, _utils().blobToBuffer)(prevContents);
|
|
129
|
+
let unusedSymbols;
|
|
130
|
+
if (bundle.env.shouldScopeHoist) {
|
|
131
|
+
unusedSymbols = [];
|
|
132
|
+
bundle.traverseAssets(asset => {
|
|
133
|
+
if (asset.symbols.isCleared || asset.meta.cssModulesCompiled === 'postcss') {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
let usedSymbols = bundleGraph.getUsedSymbols(asset);
|
|
137
|
+
if (usedSymbols == null) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let defaultImport = null;
|
|
141
|
+
if (usedSymbols.has('default')) {
|
|
142
|
+
let incoming = bundleGraph.getIncomingDependencies(asset);
|
|
143
|
+
defaultImport = incoming.find(d => d.symbols.hasExportSymbol('default'));
|
|
144
|
+
if (defaultImport) {
|
|
145
|
+
var _defaultImport$symbol;
|
|
146
|
+
let loc = (_defaultImport$symbol = defaultImport.symbols.get('default')) === null || _defaultImport$symbol === void 0 ? void 0 : _defaultImport$symbol.loc;
|
|
147
|
+
logger.warn({
|
|
148
|
+
message: 'CSS modules cannot be tree shaken when imported with a default specifier',
|
|
149
|
+
...(loc && {
|
|
150
|
+
codeFrames: [{
|
|
151
|
+
filePath: (0, _nullthrows().default)((loc === null || loc === void 0 ? void 0 : loc.filePath) ?? defaultImport.sourcePath),
|
|
152
|
+
codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(loc)]
|
|
153
|
+
}]
|
|
154
|
+
}),
|
|
155
|
+
hints: [`Instead do: import * as style from "${defaultImport.specifier}";`],
|
|
156
|
+
documentationURL: 'https://parceljs.org/languages/css/#tree-shaking'
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!defaultImport && !usedSymbols.has('*')) {
|
|
161
|
+
for (let [symbol, {
|
|
162
|
+
local
|
|
163
|
+
}] of asset.symbols) {
|
|
164
|
+
if (local !== 'default' && !usedSymbols.has(symbol)) {
|
|
165
|
+
unusedSymbols.push(local);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Inline style attributes in HTML need to be parsed differently from full CSS files.
|
|
173
|
+
if (bundle.bundleBehavior === 'inline') {
|
|
174
|
+
let entry = bundle.getMainEntry();
|
|
175
|
+
if ((entry === null || entry === void 0 ? void 0 : entry.meta.type) === 'attr') {
|
|
176
|
+
let result = (0, _lightningcss().transformStyleAttribute)({
|
|
177
|
+
code,
|
|
178
|
+
minify: true,
|
|
179
|
+
targets
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
contents: Buffer.from(result.code)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// $FlowFixMe
|
|
188
|
+
if (process.browser) {
|
|
189
|
+
await (0, _lightningcss().default)();
|
|
190
|
+
}
|
|
191
|
+
let result = (0, _lightningcss().transform)({
|
|
192
|
+
filename: bundle.name,
|
|
193
|
+
code,
|
|
194
|
+
minify: true,
|
|
195
|
+
sourceMap: !!bundle.env.sourceMap,
|
|
196
|
+
targets,
|
|
197
|
+
unusedSymbols
|
|
198
|
+
});
|
|
199
|
+
let map;
|
|
200
|
+
if (result.map != null) {
|
|
201
|
+
let vlqMap = JSON.parse(Buffer.from(result.map).toString());
|
|
202
|
+
map = new (_sourceMap().default)(options.projectRoot);
|
|
203
|
+
map.addVLQMap(vlqMap);
|
|
204
|
+
if (prevMap) {
|
|
205
|
+
map.extends(prevMap);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
let contents = Buffer.from(result.code);
|
|
209
|
+
if (bundle.env.sourceMap) {
|
|
210
|
+
let reference = await getSourceMapReference(map);
|
|
211
|
+
if (reference != null) {
|
|
212
|
+
contents = contents.toString() + '\n' + '/*# sourceMappingURL=' + reference + ' */\n';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
contents: Buffer.from(contents),
|
|
217
|
+
map
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
let cache = new Map();
|
|
222
|
+
function getTargets(browsers) {
|
|
223
|
+
if (browsers == null) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
let cached = cache.get(browsers);
|
|
227
|
+
if (cached != null) {
|
|
228
|
+
return cached;
|
|
229
|
+
}
|
|
230
|
+
let targets = (0, _lightningcss().browserslistToTargets)((0, _browserslist().default)(browsers));
|
|
231
|
+
cache.set(browsers, targets);
|
|
232
|
+
return targets;
|
|
233
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ohos-ports/parcel-optimizer-css",
|
|
3
|
+
"version": "2.16.4-beta.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"funding": {
|
|
9
|
+
"type": "opencollective",
|
|
10
|
+
"url": "https://opencollective.com/parcel"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
15
|
+
"directory": "ports/parcel-optimizer-css/2.16.4"
|
|
16
|
+
},
|
|
17
|
+
"main": "lib/CSSOptimizer.js",
|
|
18
|
+
"source": "src/CSSOptimizer.js",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">= 16.0.0",
|
|
21
|
+
"parcel": "^2.16.4"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@parcel/diagnostic": "2.16.4",
|
|
25
|
+
"@parcel/plugin": "2.16.4",
|
|
26
|
+
"@ohos-ports/parcel-source-map": "^2.1.1-beta.0",
|
|
27
|
+
"@ohos-ports/parcel-utils": "^2.16.4-beta.0",
|
|
28
|
+
"browserslist": "^4.24.5",
|
|
29
|
+
"@ohos-ports/lightningcss": "^1.33.0-1",
|
|
30
|
+
"nullthrows": "^1.1.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"lightningcss-wasm": "^1.30.1"
|
|
34
|
+
},
|
|
35
|
+
"browser": {
|
|
36
|
+
"@ohos-ports/lightningcss": "lightningcss-wasm"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "59484858a1a0bcbb71f74088956bb437a2db6505"
|
|
39
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import SourceMap from '@parcel/source-map';
|
|
4
|
+
import {Optimizer} from '@parcel/plugin';
|
|
5
|
+
// $FlowFixMe - init for browser build.
|
|
6
|
+
import init, {
|
|
7
|
+
transform,
|
|
8
|
+
transformStyleAttribute,
|
|
9
|
+
browserslistToTargets,
|
|
10
|
+
} from 'lightningcss';
|
|
11
|
+
import {blobToBuffer} from '@parcel/utils';
|
|
12
|
+
import browserslist from 'browserslist';
|
|
13
|
+
import nullthrows from 'nullthrows';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import {
|
|
16
|
+
convertSourceLocationToHighlight,
|
|
17
|
+
md,
|
|
18
|
+
generateJSONCodeHighlights,
|
|
19
|
+
} from '@parcel/diagnostic';
|
|
20
|
+
|
|
21
|
+
export default (new Optimizer({
|
|
22
|
+
async loadConfig({config, logger, options}) {
|
|
23
|
+
const configFile = await config.getConfig(
|
|
24
|
+
[
|
|
25
|
+
'.cssnanorc',
|
|
26
|
+
'cssnano.config.json',
|
|
27
|
+
'cssnano.config.js',
|
|
28
|
+
'cssnano.config.cjs',
|
|
29
|
+
],
|
|
30
|
+
{
|
|
31
|
+
packageKey: 'cssnano',
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
if (configFile) {
|
|
35
|
+
let filename = path.basename(configFile.filePath);
|
|
36
|
+
let codeHighlights;
|
|
37
|
+
let message;
|
|
38
|
+
if (filename === 'package.json') {
|
|
39
|
+
message = md`
|
|
40
|
+
Parcel\'s default CSS minifer changed from cssnano to lightningcss, but a "cssnano" key was found in **package.json**. Either remove this configuration, or configure Parcel to use @parcel/optimizer-cssnano instead.
|
|
41
|
+
`;
|
|
42
|
+
let contents = await options.inputFS.readFile(
|
|
43
|
+
configFile.filePath,
|
|
44
|
+
'utf8',
|
|
45
|
+
);
|
|
46
|
+
codeHighlights = generateJSONCodeHighlights(contents, [
|
|
47
|
+
{key: '/cssnano', type: 'key'},
|
|
48
|
+
]);
|
|
49
|
+
} else {
|
|
50
|
+
message = md`Parcel\'s default CSS minifer changed from cssnano to lightningcss, but a __${filename}__ config file was found. Either remove this config file, or configure Parcel to use @parcel/optimizer-cssnano instead.`;
|
|
51
|
+
codeHighlights = [
|
|
52
|
+
{
|
|
53
|
+
start: {line: 1, column: 1},
|
|
54
|
+
end: {line: 1, column: 1},
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
logger.warn({
|
|
60
|
+
message,
|
|
61
|
+
documentationURL: 'https://parceljs.org/languages/css/#minification',
|
|
62
|
+
codeFrames: [
|
|
63
|
+
{
|
|
64
|
+
filePath: configFile.filePath,
|
|
65
|
+
codeHighlights,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
async optimize({
|
|
72
|
+
bundle,
|
|
73
|
+
bundleGraph,
|
|
74
|
+
logger,
|
|
75
|
+
contents: prevContents,
|
|
76
|
+
getSourceMapReference,
|
|
77
|
+
map: prevMap,
|
|
78
|
+
options,
|
|
79
|
+
}) {
|
|
80
|
+
if (!bundle.env.shouldOptimize) {
|
|
81
|
+
return {contents: prevContents, map: prevMap};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let targets = getTargets(bundle.env.engines.browsers);
|
|
85
|
+
let code = await blobToBuffer(prevContents);
|
|
86
|
+
|
|
87
|
+
let unusedSymbols;
|
|
88
|
+
if (bundle.env.shouldScopeHoist) {
|
|
89
|
+
unusedSymbols = [];
|
|
90
|
+
bundle.traverseAssets(asset => {
|
|
91
|
+
if (
|
|
92
|
+
asset.symbols.isCleared ||
|
|
93
|
+
asset.meta.cssModulesCompiled === 'postcss'
|
|
94
|
+
) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let usedSymbols = bundleGraph.getUsedSymbols(asset);
|
|
99
|
+
if (usedSymbols == null) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let defaultImport = null;
|
|
104
|
+
if (usedSymbols.has('default')) {
|
|
105
|
+
let incoming = bundleGraph.getIncomingDependencies(asset);
|
|
106
|
+
defaultImport = incoming.find(d =>
|
|
107
|
+
d.symbols.hasExportSymbol('default'),
|
|
108
|
+
);
|
|
109
|
+
if (defaultImport) {
|
|
110
|
+
let loc = defaultImport.symbols.get('default')?.loc;
|
|
111
|
+
logger.warn({
|
|
112
|
+
message:
|
|
113
|
+
'CSS modules cannot be tree shaken when imported with a default specifier',
|
|
114
|
+
...(loc && {
|
|
115
|
+
codeFrames: [
|
|
116
|
+
{
|
|
117
|
+
filePath: nullthrows(
|
|
118
|
+
loc?.filePath ?? defaultImport.sourcePath,
|
|
119
|
+
),
|
|
120
|
+
codeHighlights: [convertSourceLocationToHighlight(loc)],
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
}),
|
|
124
|
+
hints: [
|
|
125
|
+
`Instead do: import * as style from "${defaultImport.specifier}";`,
|
|
126
|
+
],
|
|
127
|
+
documentationURL:
|
|
128
|
+
'https://parceljs.org/languages/css/#tree-shaking',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!defaultImport && !usedSymbols.has('*')) {
|
|
134
|
+
for (let [symbol, {local}] of asset.symbols) {
|
|
135
|
+
if (local !== 'default' && !usedSymbols.has(symbol)) {
|
|
136
|
+
unusedSymbols.push(local);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Inline style attributes in HTML need to be parsed differently from full CSS files.
|
|
144
|
+
if (bundle.bundleBehavior === 'inline') {
|
|
145
|
+
let entry = bundle.getMainEntry();
|
|
146
|
+
if (entry?.meta.type === 'attr') {
|
|
147
|
+
let result = transformStyleAttribute({
|
|
148
|
+
code,
|
|
149
|
+
minify: true,
|
|
150
|
+
targets,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
contents: Buffer.from(result.code),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// $FlowFixMe
|
|
160
|
+
if (process.browser) {
|
|
161
|
+
await init();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let result = transform({
|
|
165
|
+
filename: bundle.name,
|
|
166
|
+
code,
|
|
167
|
+
minify: true,
|
|
168
|
+
sourceMap: !!bundle.env.sourceMap,
|
|
169
|
+
targets,
|
|
170
|
+
unusedSymbols,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
let map;
|
|
174
|
+
if (result.map != null) {
|
|
175
|
+
let vlqMap = JSON.parse(Buffer.from(result.map).toString());
|
|
176
|
+
map = new SourceMap(options.projectRoot);
|
|
177
|
+
map.addVLQMap(vlqMap);
|
|
178
|
+
if (prevMap) {
|
|
179
|
+
map.extends(prevMap);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let contents = Buffer.from(result.code);
|
|
184
|
+
if (bundle.env.sourceMap) {
|
|
185
|
+
let reference = await getSourceMapReference(map);
|
|
186
|
+
if (reference != null) {
|
|
187
|
+
contents =
|
|
188
|
+
contents.toString() +
|
|
189
|
+
'\n' +
|
|
190
|
+
'/*# sourceMappingURL=' +
|
|
191
|
+
reference +
|
|
192
|
+
' */\n';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
contents: Buffer.from(contents),
|
|
198
|
+
map,
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
}): Optimizer);
|
|
202
|
+
|
|
203
|
+
let cache = new Map();
|
|
204
|
+
|
|
205
|
+
function getTargets(browsers) {
|
|
206
|
+
if (browsers == null) {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let cached = cache.get(browsers);
|
|
211
|
+
if (cached != null) {
|
|
212
|
+
return cached;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let targets = browserslistToTargets(browserslist(browsers));
|
|
216
|
+
|
|
217
|
+
cache.set(browsers, targets);
|
|
218
|
+
return targets;
|
|
219
|
+
}
|