weboptimizer 3.0.28 → 4.0.1
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 +93 -205
- package/configurator.js +222 -335
- package/ejsLoader.js +212 -170
- package/eslint.config.mjs +4 -0
- package/helper.js +230 -540
- package/index.js +245 -574
- package/jestSetup.js +7 -5
- package/package.json +31 -35
- 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 +389 -600
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.1",
|
|
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,15 @@
|
|
|
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
|
-
"clientnode": "4.0.
|
|
96
|
+
"clientnode": "4.0.1428",
|
|
101
97
|
"ejs": "^6.0.1",
|
|
102
98
|
"exports-loader": "^5.0.0",
|
|
103
99
|
"extract-loader": "^5.1.0",
|
|
@@ -110,13 +106,13 @@
|
|
|
110
106
|
"rimraf": "^6.1.3",
|
|
111
107
|
"script-loader": "^0.7.2",
|
|
112
108
|
"typescript": "^6.0.3",
|
|
113
|
-
"webpack": "^5.
|
|
114
|
-
"webpack-cli": "^7.0
|
|
109
|
+
"webpack": "^5.108.1",
|
|
110
|
+
"webpack-cli": "^7.1.0",
|
|
115
111
|
"webpack-sources": "^3.5.0"
|
|
116
112
|
},
|
|
117
113
|
"devDependencies": {
|
|
118
|
-
"@babel/cli": "^
|
|
119
|
-
"@babel/eslint-parser": "^
|
|
114
|
+
"@babel/cli": "^8.0.1",
|
|
115
|
+
"@babel/eslint-parser": "^8.0.1",
|
|
120
116
|
"@eslint/js": "^10.0.1",
|
|
121
117
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
122
118
|
"@types/ejs": "^3.1.5",
|
|
@@ -124,20 +120,20 @@
|
|
|
124
120
|
"@types/html-minifier": "^4.0.6",
|
|
125
121
|
"@types/html-minifier-terser": "^7.0.2",
|
|
126
122
|
"@types/imagemin": "^9.0.1",
|
|
127
|
-
"@types/node": "^
|
|
123
|
+
"@types/node": "^26.0.1",
|
|
128
124
|
"@types/postcss-import": "^14.0.3",
|
|
129
125
|
"@types/postcss-url": "^10.0.4",
|
|
130
126
|
"@types/webpack-env": "^1.18.8",
|
|
131
127
|
"@types/webpack-sources": "^3.2.3",
|
|
132
|
-
"@typescript-eslint/parser": "^8.
|
|
128
|
+
"@typescript-eslint/parser": "^8.62.0",
|
|
133
129
|
"css-loader": "^7.1.4",
|
|
134
130
|
"cssnano": "^8.0.2",
|
|
135
131
|
"eslint": "^10.5.0",
|
|
136
132
|
"eslint-config-google": "^0.14.0",
|
|
137
|
-
"eslint-plugin-jsdoc": "^63.0.
|
|
133
|
+
"eslint-plugin-jsdoc": "^63.0.9",
|
|
138
134
|
"favicons": "^7.3.0",
|
|
139
135
|
"favicons-webpack-plugin": "^6.0.1",
|
|
140
|
-
"globals": "^17.
|
|
136
|
+
"globals": "^17.7.0",
|
|
141
137
|
"image-minimizer-webpack-plugin": "^5.0.0",
|
|
142
138
|
"jest": "^30.4.2",
|
|
143
139
|
"jsdoc": "^4.0.5",
|
|
@@ -153,12 +149,13 @@
|
|
|
153
149
|
"postcss-url": "^10.1.4",
|
|
154
150
|
"shx": "^0.4.0",
|
|
155
151
|
"style-loader": "^4.0.0",
|
|
156
|
-
"stylelint": "^17.
|
|
152
|
+
"stylelint": "^17.14.0",
|
|
157
153
|
"stylelint-config-standard": "^40.0.0",
|
|
158
154
|
"stylelint-config-standard-scss": "^17.0.0",
|
|
159
|
-
"
|
|
155
|
+
"terser-webpack-plugin": "^5.6.1",
|
|
156
|
+
"typescript-eslint": "^8.62.0",
|
|
160
157
|
"typescript-plugin-css-modules": "^5.2.0",
|
|
161
|
-
"web-documentation": "^1.0.
|
|
158
|
+
"web-documentation": "^1.0.42",
|
|
162
159
|
"workbox-webpack-plugin": "^7.4.1"
|
|
163
160
|
},
|
|
164
161
|
"peerDependencies": {
|
|
@@ -195,6 +192,7 @@
|
|
|
195
192
|
"stylelint": "*",
|
|
196
193
|
"stylelint-config-standard": "*",
|
|
197
194
|
"stylelint-config-standard-scss": "*",
|
|
195
|
+
"terser-webpack-plugin": "*",
|
|
198
196
|
"typescript-eslint": "*",
|
|
199
197
|
"typescript-plugin-css-modules": "*",
|
|
200
198
|
"webpack-dev-server": "*",
|
|
@@ -303,6 +301,9 @@
|
|
|
303
301
|
"stylelint-config-standard-scss": {
|
|
304
302
|
"optional": true
|
|
305
303
|
},
|
|
304
|
+
"terser-webpack-plugin": {
|
|
305
|
+
"optional": true
|
|
306
|
+
},
|
|
306
307
|
"typescript-eslint": {
|
|
307
308
|
"optional": true
|
|
308
309
|
},
|
|
@@ -1178,9 +1179,7 @@
|
|
|
1178
1179
|
"minified": {
|
|
1179
1180
|
"__evaluate__": "!self.debug"
|
|
1180
1181
|
},
|
|
1181
|
-
"#": "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.",
|
|
1182
1182
|
"plugins": [
|
|
1183
|
-
"@babel/plugin-proposal-nullish-coalescing-operator",
|
|
1184
1183
|
[
|
|
1185
1184
|
"@babel/plugin-proposal-decorators",
|
|
1186
1185
|
{
|
|
@@ -1194,10 +1193,7 @@
|
|
|
1194
1193
|
}
|
|
1195
1194
|
],
|
|
1196
1195
|
[
|
|
1197
|
-
"@babel/
|
|
1198
|
-
{
|
|
1199
|
-
"loose": true
|
|
1200
|
-
}
|
|
1196
|
+
"@babel/plugin-transform-class-properties"
|
|
1201
1197
|
],
|
|
1202
1198
|
[
|
|
1203
1199
|
"transform-modern-regexp",
|
|
@@ -1208,11 +1204,11 @@
|
|
|
1208
1204
|
]
|
|
1209
1205
|
}
|
|
1210
1206
|
],
|
|
1211
|
-
"
|
|
1207
|
+
"babel-plugin-polyfill-corejs3"
|
|
1212
1208
|
],
|
|
1213
1209
|
"presets": {
|
|
1214
1210
|
"#": "NOTE: We have to disable module export/import transformation to allow tree shaking by the final (minimizer).",
|
|
1215
|
-
"__evaluate__": "[['@babel/preset-env', {
|
|
1211
|
+
"__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]])"
|
|
1216
1212
|
}
|
|
1217
1213
|
},
|
|
1218
1214
|
"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
|
|