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