1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.buildOptimizerLoaderPath = void 0;
|
11 | const webpack_1 = require("webpack");
|
12 | const build_optimizer_1 = require("./build-optimizer");
|
13 | exports.buildOptimizerLoaderPath = __filename;
|
14 | const alwaysProcess = (path) => path.endsWith('.ts') || path.endsWith('.tsx');
|
15 | function buildOptimizerLoader(content, previousSourceMap) {
|
16 | this.cacheable();
|
17 | const skipBuildOptimizer = this._module && this._module.factoryMeta && this._module.factoryMeta.skipBuildOptimizer;
|
18 | if (!alwaysProcess(this.resourcePath) && skipBuildOptimizer) {
|
19 |
|
20 |
|
21 | this.callback(null, content, previousSourceMap);
|
22 | return;
|
23 | }
|
24 | const options = (this.getOptions() || {});
|
25 | const boOutput = (0, build_optimizer_1.buildOptimizer)({
|
26 | content,
|
27 | originalFilePath: this.resourcePath,
|
28 | inputFilePath: this.resourcePath,
|
29 | outputFilePath: this.resourcePath,
|
30 | emitSourceMap: options.sourceMap,
|
31 | isSideEffectFree: this._module && this._module.factoryMeta && this._module.factoryMeta.sideEffectFree,
|
32 | });
|
33 | if (boOutput.emitSkipped || boOutput.content === null) {
|
34 | this.callback(null, content, previousSourceMap);
|
35 | return;
|
36 | }
|
37 | const intermediateSourceMap = boOutput.sourceMap;
|
38 | let newContent = boOutput.content;
|
39 | let newSourceMap;
|
40 | if (options.sourceMap && intermediateSourceMap) {
|
41 |
|
42 | newContent = newContent.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
|
43 | if (previousSourceMap) {
|
44 |
|
45 | newSourceMap = new webpack_1.sources.SourceMapSource(newContent, this.resourcePath, intermediateSourceMap, content, previousSourceMap, true).map();
|
46 | }
|
47 | else {
|
48 |
|
49 | newSourceMap = intermediateSourceMap;
|
50 | }
|
51 | }
|
52 | this.callback(null, newContent, newSourceMap);
|
53 | }
|
54 | exports.default = buildOptimizerLoader;
|