UNPKG

1.72 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = loader;
7Object.defineProperty(exports, "defaultMinimizerOptions", {
8 enumerable: true,
9 get: function () {
10 return _utils.defaultMinimizerOptions;
11 }
12});
13
14var _plugins = require("./plugins");
15
16var _utils = require("./utils");
17
18var _options = _interopRequireDefault(require("./options.json"));
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22async function loader(content) {
23 const rawOptions = this.getOptions(_options.default);
24 const options = (0, _utils.normalizeOptions)(rawOptions, this);
25
26 if (options.preprocessor) {
27 // eslint-disable-next-line no-param-reassign
28 content = await options.preprocessor(content, this);
29 }
30
31 const plugins = [];
32 const errors = [];
33 const imports = [];
34 const replacements = [];
35
36 if (options.sources) {
37 plugins.push((0, _plugins.sourcesPlugin)({
38 sources: options.sources,
39 resourcePath: this.resourcePath,
40 context: this.context,
41 imports,
42 errors,
43 replacements
44 }));
45 }
46
47 if (options.minimize) {
48 plugins.push((0, _plugins.minimizerPlugin)({
49 minimize: options.minimize,
50 errors
51 }));
52 }
53
54 const {
55 html
56 } = await (0, _utils.pluginRunner)(plugins).process(content);
57
58 for (const error of errors) {
59 this.emitError(error instanceof Error ? error : new Error(error));
60 }
61
62 const importCode = (0, _utils.getImportCode)(html, this, imports, options);
63 const moduleCode = (0, _utils.getModuleCode)(html, replacements, options);
64 const exportCode = (0, _utils.getExportCode)(html, options);
65 return `${importCode}${moduleCode}${exportCode}`;
66}
\No newline at end of file