weboptimizer 3.0.29 → 4.0.2
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/browser.js +92 -204
- package/configurator.js +221 -334
- package/ejsLoader.js +211 -169
- package/eslint.config.mjs +4 -0
- package/helper.js +229 -539
- package/index.js +244 -573
- package/jestSetup.js +7 -5
- package/package.json +18 -26
- package/plugins/HTMLTransformation.js +68 -109
- package/plugins/InPlaceAssetsIntoHTML.js +66 -69
- package/stylelintConfigurator.js +4 -8
- package/type.js +15 -6
- package/webpackConfigurator.js +388 -599
package/jestSetup.js
CHANGED
|
@@ -16,12 +16,14 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
import { globalContext } from 'clientnode';
|
|
20
|
+
import { TextEncoder, TextDecoder } from 'util'
|
|
21
|
+
// endregion
|
|
22
|
+
;
|
|
23
|
+
globalContext.TextEncoder = TextEncoder;
|
|
24
|
+
globalContext.TextDecoder = TextDecoder;
|
|
23
25
|
try {
|
|
24
26
|
if (eval('require')('jest-canvas-mock')) console.info('Canvas mocking module loaded.');
|
|
25
|
-
} catch
|
|
27
|
+
} catch {
|
|
26
28
|
// Do nothing.
|
|
27
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weboptimizer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "A generic web optimizer, (module) bundler and development environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "yarn build:types; yarn build:lint; yarn build:plain",
|
|
66
|
-
"build:lint": " babel --extensions '.ts' --
|
|
67
|
-
"build:plain": "command=\"babel --extensions '.ts' --
|
|
66
|
+
"build:lint": " babel --extensions '.ts' --out-file eslint.config.mjs eslint.config.ts",
|
|
67
|
+
"build:plain": "command=\"babel --extensions '.ts' --out-file\" && $command browser.js browser.ts && $command configurator.js configurator.ts && $command ejsLoader.js ejsLoader.ts && $command helper.js helper.ts && $command index.js index.ts && $command jestSetup.js jestSetup.ts && $command plugins/HTMLTransformation.js plugins/HTMLTransformation.ts && $command plugins/InPlaceAssetsIntoHTML.js plugins/InPlaceAssetsIntoHTML.ts && $command stylelintConfigurator.js stylelintConfigurator.ts && $command type.js type.ts && $command webpackConfigurator.js webpackConfigurator.ts && shx chmod +x index.js && shx sed -i 's/(#!\\\\/usr\\\\/bin\\\\/env )babel-(node)/$1$2/' index.js 1>/dev/null",
|
|
68
68
|
"build:copy-test-artefacts": "cd test/simple && shx touch yarn.lock && rimraf node_modules && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install; cd ../../ && cd test/scss && shx touch yarn.lock && rimraf node_modules && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install; cd ../../ && rimraf node_modules/weboptimizer test/simple/node_modules/weboptimizer test/scss/node_modules/weboptimizer && shx mkdir -p node_modules/weboptimizer test/simple/node_modules/weboptimizer test/scss/node_modules/weboptimizer && copyCommand='shx cp -r plugins *.ts *.js *.mjs *.json *.ejs' && $copyCommand node_modules/weboptimizer/ && $copyCommand test/simple/node_modules/weboptimizer/ && $copyCommand test/scss/node_modules/weboptimizer/",
|
|
69
|
-
"build:test": " yarn clear && yarn build && command='babel --extensions '.ts' --
|
|
70
|
-
"build:test:source-map": "yarn clear && yarn build && command='babel --extensions '.ts' --
|
|
69
|
+
"build:test": " yarn clear && yarn build && command='babel --extensions '.ts' --source-root ../ --out-file' && yarn build:copy-test-artefacts && $command test/browser.js test/browser.ts && $command test/configurator.js test/configurator.ts && $command test/helper.js test/helper.ts && $command test/ejsLoader.js test/ejsLoader.ts && $command test/stylelintConfigurator.js test/stylelintConfigurator.ts && $command test/index.js test/index.ts && $command test/webpackConfigurator.js test/webpackConfigurator.ts",
|
|
70
|
+
"build:test:source-map": "yarn clear && yarn build && command='babel --extensions '.ts' --source-maps inline --source-root ../ --out-file' && yarn build:copy-test-artefacts && $command test/browser.js test/browser.ts && $command test/configurator.js test/configurator.ts && $command test/helper.js test/helper.ts && $command test/ejsLoader.js test/ejsLoader.ts && $command test/stylelintConfigurator.js test/stylelintConfigurator.ts && $command test/index.js test/index.ts && $command test/webpackConfigurator.js test/webpackConfigurator.ts",
|
|
71
71
|
"build:types": "tsc --declaration --emitDeclarationOnly",
|
|
72
72
|
"check": "yarn check:types; yarn lint",
|
|
73
73
|
"check:types": "tsc --noEmit",
|
|
@@ -85,19 +85,16 @@
|
|
|
85
85
|
"update:documentation": "web-documentation"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@babel/core": "^
|
|
89
|
-
"@babel/plugin-proposal-
|
|
90
|
-
"@babel/plugin-
|
|
91
|
-
"@babel/
|
|
92
|
-
"@babel/
|
|
93
|
-
"@babel/plugin-transform-runtime": "^7.29.7",
|
|
94
|
-
"@babel/preset-env": "^7.29.7",
|
|
95
|
-
"@babel/preset-typescript": "^7.29.7",
|
|
96
|
-
"@babel/runtime": "^7.29.7",
|
|
88
|
+
"@babel/core": "^8.0.1",
|
|
89
|
+
"@babel/plugin-proposal-decorators": "^8.0.2",
|
|
90
|
+
"@babel/plugin-transform-class-properties": "^8.0.1",
|
|
91
|
+
"@babel/preset-env": "^8.0.2",
|
|
92
|
+
"@babel/preset-typescript": "^8.0.1",
|
|
97
93
|
"babel-loader": "^10.1.1",
|
|
98
|
-
"babel-plugin-
|
|
94
|
+
"babel-plugin-polyfill-corejs3": "^1.0.0",
|
|
99
95
|
"babel-preset-minify": "^0.5.2",
|
|
100
96
|
"clientnode": "4.0.1428",
|
|
97
|
+
"core-js": "^3.49.0",
|
|
101
98
|
"ejs": "^6.0.1",
|
|
102
99
|
"exports-loader": "^5.0.0",
|
|
103
100
|
"extract-loader": "^5.1.0",
|
|
@@ -115,8 +112,8 @@
|
|
|
115
112
|
"webpack-sources": "^3.5.0"
|
|
116
113
|
},
|
|
117
114
|
"devDependencies": {
|
|
118
|
-
"@babel/cli": "^
|
|
119
|
-
"@babel/eslint-parser": "^
|
|
115
|
+
"@babel/cli": "^8.0.1",
|
|
116
|
+
"@babel/eslint-parser": "^8.0.1",
|
|
120
117
|
"@eslint/js": "^10.0.1",
|
|
121
118
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
122
119
|
"@types/ejs": "^3.1.5",
|
|
@@ -124,7 +121,7 @@
|
|
|
124
121
|
"@types/html-minifier": "^4.0.6",
|
|
125
122
|
"@types/html-minifier-terser": "^7.0.2",
|
|
126
123
|
"@types/imagemin": "^9.0.1",
|
|
127
|
-
"@types/node": "^
|
|
124
|
+
"@types/node": "^26.0.1",
|
|
128
125
|
"@types/postcss-import": "^14.0.3",
|
|
129
126
|
"@types/postcss-url": "^10.0.4",
|
|
130
127
|
"@types/webpack-env": "^1.18.8",
|
|
@@ -1183,9 +1180,7 @@
|
|
|
1183
1180
|
"minified": {
|
|
1184
1181
|
"__evaluate__": "!self.debug"
|
|
1185
1182
|
},
|
|
1186
|
-
"#": "NOTE: \"@babel/plugin-proposal-nullish-coalescing-operator\" and \"@babel/plugin-proposal-optional-chaining\" is needed to let typescript be able to parse result. \"@babel/plugin-transform-parameters\" is needed caused by a bug when transforming parameters coming from the preceding transformer.",
|
|
1187
1183
|
"plugins": [
|
|
1188
|
-
"@babel/plugin-proposal-nullish-coalescing-operator",
|
|
1189
1184
|
[
|
|
1190
1185
|
"@babel/plugin-proposal-decorators",
|
|
1191
1186
|
{
|
|
@@ -1199,10 +1194,7 @@
|
|
|
1199
1194
|
}
|
|
1200
1195
|
],
|
|
1201
1196
|
[
|
|
1202
|
-
"@babel/
|
|
1203
|
-
{
|
|
1204
|
-
"loose": true
|
|
1205
|
-
}
|
|
1197
|
+
"@babel/plugin-transform-class-properties"
|
|
1206
1198
|
],
|
|
1207
1199
|
[
|
|
1208
1200
|
"transform-modern-regexp",
|
|
@@ -1213,11 +1205,11 @@
|
|
|
1213
1205
|
]
|
|
1214
1206
|
}
|
|
1215
1207
|
],
|
|
1216
|
-
"
|
|
1208
|
+
"babel-plugin-polyfill-corejs3"
|
|
1217
1209
|
],
|
|
1218
1210
|
"presets": {
|
|
1219
1211
|
"#": "NOTE: We have to disable module export/import transformation to allow tree shaking by the final (minimizer).",
|
|
1220
|
-
"__evaluate__": "[['@babel/preset-env', {
|
|
1212
|
+
"__evaluate__": "[['@babel/preset-env', {modules: false, targets: self.generic.isWeb ? {browsers: self.generic.supportedBrowsers, node: packageConfiguration.engines.node.replace(/>?=?([0-9]+)/, '$1')} : {node: packageConfiguration.engines.node.replace(/>?=?([0-9]+)/, '$1')}}], '@babel/preset-typescript'].concat((self.debug || !self.module.optimizer.babelMinify.module || 2 < self.givenCommandLineArguments.length && self.givenCommandLineArguments[2] === 'document') ? [] : [['minify', self.module.optimizer.babelMinify.module]])"
|
|
1221
1213
|
}
|
|
1222
1214
|
},
|
|
1223
1215
|
"regularExpression": "\\.[jt]sx?(?:\\?.*)?$"
|
|
@@ -16,119 +16,78 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _jsdom = require("jsdom");
|
|
30
|
-
var _ejsLoader = _interopRequireDefault(require("../ejsLoader"));
|
|
31
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
32
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
33
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
34
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
35
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
import "core-js/modules/es.array.push.js";
|
|
20
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
22
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
|
+
import { copy, extend, Mapping } from 'clientnode';
|
|
24
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
25
|
+
import { JSDOM as DOM } from 'jsdom';
|
|
26
|
+
import { Compilation, Compiler, LoaderContext } from 'webpack';
|
|
27
|
+
import ejsLoader, { LoaderConfiguration as EJSLoaderConfiguration } from '../ejsLoader';
|
|
28
|
+
import { HTMLTransformationOptions, HTMLWebpackPluginBeforeEmitData, WebpackLoader } from '../type';
|
|
36
29
|
// endregion
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(
|
|
41
|
-
(
|
|
42
|
-
this.options =
|
|
30
|
+
|
|
31
|
+
export class HTMLTransformation {
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
_defineProperty(this, "defaultOptions", {});
|
|
34
|
+
_defineProperty(this, "options", void 0);
|
|
35
|
+
this.options = {
|
|
36
|
+
...this.defaultOptions,
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
process(data) {
|
|
41
|
+
/*
|
|
42
|
+
NOTE: We have to prevent creating native "style" dom nodes to
|
|
43
|
+
prevent jsdom from parsing the entire cascading style sheet. Which
|
|
44
|
+
is error prune and very resource intensive.
|
|
45
|
+
*/
|
|
46
|
+
const styleContents = [];
|
|
47
|
+
data.html = data.html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style[^>]*>)/gi, (match, startTag, content, endTag) => {
|
|
48
|
+
styleContents.push(content);
|
|
49
|
+
return `${startTag}${endTag}`;
|
|
50
|
+
});
|
|
51
|
+
let dom;
|
|
52
|
+
try {
|
|
47
53
|
/*
|
|
48
|
-
NOTE: We have to
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
NOTE: We have to translate template delimiter to html
|
|
55
|
+
compatible sequences and translate it back later to avoid
|
|
56
|
+
unexpected escape sequences in resulting html.
|
|
51
57
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
styleContents.push(content);
|
|
55
|
-
return "".concat(startTag).concat(endTag);
|
|
56
|
-
});
|
|
57
|
-
var dom;
|
|
58
|
-
try {
|
|
59
|
-
/*
|
|
60
|
-
NOTE: We have to translate template delimiter to html
|
|
61
|
-
compatible sequences and translate it back later to avoid
|
|
62
|
-
unexpected escape sequences in resulting html.
|
|
63
|
-
*/
|
|
64
|
-
dom = new _jsdom.JSDOM(data.html.replace(/<%/g, '##+#+#+##').replace(/%>/g, '##-#-#-##'));
|
|
65
|
-
} catch (_unused) {
|
|
66
|
-
return data;
|
|
67
|
-
}
|
|
68
|
-
var linkables = {
|
|
69
|
-
link: 'href',
|
|
70
|
-
script: 'src'
|
|
71
|
-
};
|
|
72
|
-
for (var _i = 0, _Object$entries = Object.entries(linkables); _i < _Object$entries.length; _i++) {
|
|
73
|
-
var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2),
|
|
74
|
-
tagName = _Object$entries$_i[0],
|
|
75
|
-
attributeName = _Object$entries$_i[1];
|
|
76
|
-
for (var _i2 = 0, _Array$from = Array.from(dom.window.document.querySelectorAll("".concat(tagName, "[").concat(attributeName, "*=\"?") + "".concat(this.options.hashAlgorithm, "=\"]"))); _i2 < _Array$from.length; _i2++) {
|
|
77
|
-
var domNode = _Array$from[_i2];
|
|
78
|
-
/*
|
|
79
|
-
NOTE: Removing symbols after a "&" in hash string is
|
|
80
|
-
necessary to match the generated request strings in offline
|
|
81
|
-
plugin.
|
|
82
|
-
*/
|
|
83
|
-
var value = domNode.getAttribute(attributeName);
|
|
84
|
-
if (value) domNode.setAttribute(attributeName, value.replace(new RegExp("(\\?".concat(this.options.hashAlgorithm, "=[^&]+).*$")), '$1'));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// NOTE: We have to restore template delimiter and style contents.
|
|
88
|
-
data.html = dom.serialize().replace(/##\+#\+#\+##/g, '<%').replace(/##-#-#-##/g, '%>').replace(/(<style[^>]*>)[\s\S]*?(<\/style[^>]*>)/gi, function (match, startTag, endTag) {
|
|
89
|
-
return "".concat(startTag).concat(styleContents.shift()).concat(endTag);
|
|
90
|
-
});
|
|
91
|
-
// region post compilation
|
|
92
|
-
var _iterator = _createForOfIteratorHelper(this.options.files),
|
|
93
|
-
_step;
|
|
94
|
-
try {
|
|
95
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
96
|
-
var htmlFileSpecification = _step.value;
|
|
97
|
-
if (htmlFileSpecification.filename === data.plugin.options.filename) {
|
|
98
|
-
var _iterator2 = _createForOfIteratorHelper([].concat(htmlFileSpecification.template.use)),
|
|
99
|
-
_step2;
|
|
100
|
-
try {
|
|
101
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
102
|
-
var _loaderConfiguration$;
|
|
103
|
-
var loaderConfiguration = _step2.value;
|
|
104
|
-
if ((_loaderConfiguration$ = loaderConfiguration.options) !== null && _loaderConfiguration$ !== void 0 && _loaderConfiguration$.compileSteps && typeof loaderConfiguration.options.compileSteps === 'number') data.html = _ejsLoader["default"].bind({
|
|
105
|
-
query: (0, _clientnode.extend)(true, Object.prototype.hasOwnProperty.call(loaderConfiguration, 'options') ? (0, _clientnode.copy)(loaderConfiguration.options) : {}, htmlFileSpecification.template.postCompileOptions)
|
|
106
|
-
})(data.html);
|
|
107
|
-
}
|
|
108
|
-
} catch (err) {
|
|
109
|
-
_iterator2.e(err);
|
|
110
|
-
} finally {
|
|
111
|
-
_iterator2.f();
|
|
112
|
-
}
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// endregion
|
|
117
|
-
} catch (err) {
|
|
118
|
-
_iterator.e(err);
|
|
119
|
-
} finally {
|
|
120
|
-
_iterator.f();
|
|
121
|
-
}
|
|
58
|
+
dom = new DOM(data.html.replace(/<%/g, '##+#+#+##').replace(/%>/g, '##-#-#-##'));
|
|
59
|
+
} catch {
|
|
122
60
|
return data;
|
|
123
61
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
62
|
+
const linkables = {
|
|
63
|
+
link: 'href',
|
|
64
|
+
script: 'src'
|
|
65
|
+
};
|
|
66
|
+
for (const [tagName, attributeName] of Object.entries(linkables)) for (const domNode of Array.from(dom.window.document.querySelectorAll(`${tagName}[${attributeName}*="?` + `${this.options.hashAlgorithm}="]`))) {
|
|
67
|
+
/*
|
|
68
|
+
NOTE: Removing symbols after a "&" in hash string is
|
|
69
|
+
necessary to match the generated request strings in offline
|
|
70
|
+
plugin.
|
|
71
|
+
*/
|
|
72
|
+
const value = domNode.getAttribute(attributeName);
|
|
73
|
+
if (value) domNode.setAttribute(attributeName, value.replace(new RegExp(`(\\?${this.options.hashAlgorithm}=[^&]+).*$`), '$1'));
|
|
74
|
+
}
|
|
75
|
+
// NOTE: We have to restore template delimiter and style contents.
|
|
76
|
+
data.html = dom.serialize().replace(/##\+#\+#\+##/g, '<%').replace(/##-#-#-##/g, '%>').replace(/(<style[^>]*>)[\s\S]*?(<\/style[^>]*>)/gi, (match, startTag, endTag) => `${startTag}${styleContents.shift()}${endTag}`);
|
|
77
|
+
// region post compilation
|
|
78
|
+
for (const htmlFileSpecification of this.options.files) if (htmlFileSpecification.filename === data.plugin.options.filename) {
|
|
79
|
+
for (const loaderConfiguration of [].concat(htmlFileSpecification.template.use)) if (loaderConfiguration.options?.compileSteps && typeof loaderConfiguration.options.compileSteps === 'number') data.html = ejsLoader.bind({
|
|
80
|
+
query: extend(true, Object.prototype.hasOwnProperty.call(loaderConfiguration, 'options') ? copy(loaderConfiguration.options) : {}, htmlFileSpecification.template.postCompileOptions)
|
|
81
|
+
})(data.html);
|
|
82
|
+
break;
|
|
131
83
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
84
|
+
// endregion
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
apply(compiler) {
|
|
88
|
+
compiler.hooks.compilation.tap('WebOptimizer', compilation => {
|
|
89
|
+
this.options.htmlPlugin.getHooks(compilation).beforeEmit.tap('WebOptimizerPostProcessHTML', this.process.bind(this));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export default HTMLTransformation;
|
|
@@ -16,76 +16,73 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
import "core-js/modules/es.array.push.js";
|
|
20
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
21
|
+
import "core-js/modules/es.iterator.map.js";
|
|
22
|
+
import "core-js/modules/es.iterator.some.js";
|
|
23
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
25
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
|
+
import { Compilation, Compiler } from 'webpack';
|
|
27
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
28
|
+
import { InPlaceAssetConfiguration, InPlaceAssetsIntoHTMLOptions, WebpackAssets, WebpackBaseAssets } from '../type';
|
|
29
29
|
// endregion
|
|
30
|
-
var InPlaceAssetsIntoHTML = exports.InPlaceAssetsIntoHTML = /*#__PURE__*/function () {
|
|
31
|
-
function InPlaceAssetsIntoHTML() {
|
|
32
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
33
|
-
(0, _classCallCheck2["default"])(this, InPlaceAssetsIntoHTML);
|
|
34
|
-
(0, _defineProperty2["default"])(this, "defaultOptions", {});
|
|
35
|
-
this.options = _objectSpread(_objectSpread({}, this.defaultOptions), options);
|
|
36
|
-
}
|
|
37
|
-
return (0, _createClass2["default"])(InPlaceAssetsIntoHTML, [{
|
|
38
|
-
key: "apply",
|
|
39
|
-
value: function apply(compiler) {
|
|
40
|
-
var _this = this;
|
|
41
|
-
var publicPath = compiler.options.output.publicPath || '';
|
|
42
|
-
if (publicPath && !publicPath.endsWith('/')) publicPath += '/';
|
|
43
|
-
compiler.hooks.compilation.tap('inPlaceHTMLAssets', function (compilation) {
|
|
44
|
-
var hooks = _this.options.htmlPlugin.getHooks(compilation);
|
|
45
|
-
var inPlacedAssetNames = [];
|
|
46
|
-
hooks.alterAssetTagGroups.tap('inPlaceHTMLAssets', function (assets) {
|
|
47
|
-
var inPlace = function inPlace(type, tag) {
|
|
48
|
-
var settings = null;
|
|
49
|
-
var url = false;
|
|
50
|
-
if (tag.tagName === 'script') {
|
|
51
|
-
settings = _this.options.javaScript;
|
|
52
|
-
url = tag.attributes.src;
|
|
53
|
-
} else if (tag.tagName === 'style') {
|
|
54
|
-
settings = _this.options.cascadingStyleSheet;
|
|
55
|
-
url = tag.attributes.href;
|
|
56
|
-
}
|
|
57
|
-
if (!(url && typeof url === 'string')) return tag;
|
|
58
|
-
var name = publicPath ? url.replace(publicPath, '') : url;
|
|
59
|
-
if (Object.prototype.hasOwnProperty.call(compilation.assets, name) && settings && settings[type] && [].concat(settings[type]).some(function (pattern) {
|
|
60
|
-
return new RegExp(pattern).test(name);
|
|
61
|
-
})) {
|
|
62
|
-
var newAttributes = _objectSpread({}, tag.attributes);
|
|
63
|
-
delete newAttributes.href;
|
|
64
|
-
delete newAttributes.src;
|
|
65
|
-
inPlacedAssetNames.push(name);
|
|
66
|
-
return _objectSpread(_objectSpread({}, tag), {}, {
|
|
67
|
-
attributes: newAttributes,
|
|
68
|
-
innerHTML: compilation.assets[name].source(),
|
|
69
|
-
tagName: 'script'
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return tag;
|
|
73
|
-
};
|
|
74
|
-
assets.headTags = assets.headTags.map(inPlace.bind(_this, 'head'));
|
|
75
|
-
assets.bodyTags = assets.bodyTags.map(inPlace.bind(_this, 'body'));
|
|
76
|
-
return assets;
|
|
77
|
-
});
|
|
78
30
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
31
|
+
export class InPlaceAssetsIntoHTML {
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
_defineProperty(this, "defaultOptions", {});
|
|
34
|
+
_defineProperty(this, "options", void 0);
|
|
35
|
+
this.options = {
|
|
36
|
+
...this.defaultOptions,
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
apply(compiler) {
|
|
41
|
+
let publicPath = compiler.options.output.publicPath || '';
|
|
42
|
+
if (publicPath && !publicPath.endsWith('/')) publicPath += '/';
|
|
43
|
+
compiler.hooks.compilation.tap('inPlaceHTMLAssets', compilation => {
|
|
44
|
+
const hooks = this.options.htmlPlugin.getHooks(compilation);
|
|
45
|
+
const inPlacedAssetNames = [];
|
|
46
|
+
hooks.alterAssetTagGroups.tap('inPlaceHTMLAssets', assets => {
|
|
47
|
+
const inPlace = (type, tag) => {
|
|
48
|
+
let settings = null;
|
|
49
|
+
let url = false;
|
|
50
|
+
if (tag.tagName === 'script') {
|
|
51
|
+
settings = this.options.javaScript;
|
|
52
|
+
url = tag.attributes.src;
|
|
53
|
+
} else if (tag.tagName === 'style') {
|
|
54
|
+
settings = this.options.cascadingStyleSheet;
|
|
55
|
+
url = tag.attributes.href;
|
|
56
|
+
}
|
|
57
|
+
if (!(url && typeof url === 'string')) return tag;
|
|
58
|
+
const name = publicPath ? url.replace(publicPath, '') : url;
|
|
59
|
+
if (Object.prototype.hasOwnProperty.call(compilation.assets, name) && settings && settings[type] && [].concat(settings[type]).some(pattern => new RegExp(pattern).test(name))) {
|
|
60
|
+
const newAttributes = {
|
|
61
|
+
...tag.attributes
|
|
62
|
+
};
|
|
63
|
+
delete newAttributes.href;
|
|
64
|
+
delete newAttributes.src;
|
|
65
|
+
inPlacedAssetNames.push(name);
|
|
66
|
+
return {
|
|
67
|
+
...tag,
|
|
68
|
+
attributes: newAttributes,
|
|
69
|
+
innerHTML: compilation.assets[name].source(),
|
|
70
|
+
tagName: 'script'
|
|
71
|
+
};
|
|
84
72
|
}
|
|
85
|
-
return
|
|
86
|
-
}
|
|
73
|
+
return tag;
|
|
74
|
+
};
|
|
75
|
+
assets.headTags = assets.headTags.map(inPlace.bind(this, 'head'));
|
|
76
|
+
assets.bodyTags = assets.bodyTags.map(inPlace.bind(this, 'body'));
|
|
77
|
+
return assets;
|
|
87
78
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
|
|
80
|
+
// NOTE: Avoid if you still want to emit the runtime chunks:
|
|
81
|
+
hooks.afterEmit.tap('inPlaceHTMLAssets', asset => {
|
|
82
|
+
for (const name of inPlacedAssetNames) delete compilation.assets[name];
|
|
83
|
+
return asset;
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export default InPlaceAssetsIntoHTML;
|
package/stylelintConfigurator.js
CHANGED
|
@@ -16,13 +16,9 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
value: true
|
|
22
|
-
});
|
|
23
|
-
exports["default"] = void 0;
|
|
24
|
-
var _configurator = _interopRequireDefault(require("./configurator"));
|
|
19
|
+
import getConfiguration from './configurator';
|
|
20
|
+
import { ResolvedConfiguration } from './type';
|
|
25
21
|
// endregion
|
|
26
|
-
|
|
22
|
+
const configuration = getConfiguration();
|
|
27
23
|
module.exports = configuration.stylelint;
|
|
28
|
-
|
|
24
|
+
export default module.exports;
|
package/type.js
CHANGED
|
@@ -16,24 +16,33 @@
|
|
|
16
16
|
endregion
|
|
17
17
|
*/
|
|
18
18
|
// region imports
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
import { AnyFunction, Encoding, Mapping, PlainObject, SecondParameter } from 'clientnode';
|
|
20
|
+
import { FaviconWebpackPlugionOptions as FaviconWebpackPluginOptions } from 'favicons-webpack-plugin/src/options';
|
|
21
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
22
|
+
import { PluginOptions as ImageMinimizerOptions } from 'image-minimizer-webpack-plugin';
|
|
23
|
+
import { JSDOM } from 'jsdom';
|
|
24
|
+
import { DefinePlugin as WebpackDefinePlugin, Configuration as BaseWebpackConfiguration, IgnorePlugin as WebpackIgnorePlugin, library as webpackLibrary, ModuleOptions as WebpackModuleOptions, RuleSetRule as WebpackRuleSetRule, RuleSetUseItem as WebpackRuleSetUseItem, WebpackOptionsNormalized } from 'webpack';
|
|
25
|
+
import { WebpackPartial as WorkboxBaseCommonOptions, BasePartial as WorkboxCommonOptions, WebpackGenerateSWOptions as WorkboxGenerateSWOptions, WebpackInjectManifestOptions as WorkboxInjectManifestOptions } from 'workbox-build';
|
|
26
|
+
|
|
23
27
|
// endregion
|
|
24
28
|
// region exports
|
|
25
29
|
/// region generic
|
|
30
|
+
|
|
26
31
|
/// endregion
|
|
27
32
|
/// region injection
|
|
33
|
+
|
|
28
34
|
/// endregion
|
|
29
35
|
/// region configuration
|
|
30
36
|
// region plugins
|
|
37
|
+
|
|
31
38
|
// endregion
|
|
32
39
|
//// region path
|
|
40
|
+
|
|
33
41
|
//// endregion
|
|
34
42
|
//// region build
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
|
|
44
|
+
export const SubConfigurationTypes = ['debug', 'document', 'test', 'test:browser'];
|
|
45
|
+
export const TaskTypes = ['build', 'serve', ...SubConfigurationTypes];
|
|
37
46
|
//// endregion
|
|
38
47
|
//// region loader
|
|
39
48
|
|