weboptimizer 2.0.1419 → 2.0.1421
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weboptimizer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1421",
|
|
4
4
|
"description": "A generic web optimizer, (module) bundler and development environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -42,8 +42,10 @@
|
|
|
42
42
|
"jestEnvironmentBrowser.js",
|
|
43
43
|
"jestSetup.d.ts",
|
|
44
44
|
"jestSetup.js",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"plugins/HTMLTransformation.d.ts",
|
|
46
|
+
"plugins/HTMLTransformation.js",
|
|
47
|
+
"plugins/InPlaceAssetsIntoHTML.d.ts",
|
|
48
|
+
"plugins/InPlaceAssetsIntoHTML.js",
|
|
47
49
|
"stylelintConfigurator.d.ts",
|
|
48
50
|
"stylelintConfigurator.js",
|
|
49
51
|
"tsconfig.json",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
import { HTMLTransformationOptions } from '../type';
|
|
3
|
+
export declare class HTMLTransformation {
|
|
4
|
+
private defaultOptions;
|
|
5
|
+
private options;
|
|
6
|
+
constructor(options?: Partial<HTMLTransformationOptions>);
|
|
7
|
+
apply(compiler: Compiler): void;
|
|
8
|
+
}
|
|
9
|
+
export default HTMLTransformation;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// #!/usr/bin/env babel-node
|
|
2
|
+
// -*- coding: utf-8 -*-
|
|
3
|
+
/** @module InPlaceAssetsIntoHTML */
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/* !
|
|
7
|
+
region header
|
|
8
|
+
Copyright Torben Sickert (info["~at~"]torben.website) 16.12.2012
|
|
9
|
+
|
|
10
|
+
License
|
|
11
|
+
-------
|
|
12
|
+
|
|
13
|
+
This library written by Torben Sickert stand under a creative commons
|
|
14
|
+
naming 3.0 unported license.
|
|
15
|
+
See https://creativecommons.org/licenses/by/3.0/deed.de
|
|
16
|
+
endregion
|
|
17
|
+
*/
|
|
18
|
+
// region imports
|
|
19
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
20
|
+
Object.defineProperty(exports, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
});
|
|
23
|
+
exports["default"] = exports.HTMLTransformation = void 0;
|
|
24
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
25
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
26
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
27
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
28
|
+
var _clientnode = _interopRequireDefault(require("clientnode"));
|
|
29
|
+
var _jsdom = require("jsdom");
|
|
30
|
+
var _ejsLoader = _interopRequireDefault(require("../ejsLoader"));
|
|
31
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
32
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
33
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
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; }
|
|
36
|
+
// endregion
|
|
37
|
+
var HTMLTransformation = exports.HTMLTransformation = /*#__PURE__*/function () {
|
|
38
|
+
function HTMLTransformation() {
|
|
39
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
40
|
+
(0, _classCallCheck2["default"])(this, HTMLTransformation);
|
|
41
|
+
(0, _defineProperty2["default"])(this, "defaultOptions", {});
|
|
42
|
+
(0, _defineProperty2["default"])(this, "options", void 0);
|
|
43
|
+
this.options = _objectSpread(_objectSpread({}, this.defaultOptions), options);
|
|
44
|
+
}
|
|
45
|
+
(0, _createClass2["default"])(HTMLTransformation, [{
|
|
46
|
+
key: "apply",
|
|
47
|
+
value: function apply(compiler) {
|
|
48
|
+
var _this = this;
|
|
49
|
+
compiler.hooks.compilation.tap('WebOptimizer', function (compilation) {
|
|
50
|
+
_this.options.htmlPlugin.getHooks(compilation).beforeEmit.tap('WebOptimizerPostProcessHTML', function (data) {
|
|
51
|
+
/*
|
|
52
|
+
NOTE: We have to prevent creating native "style" dom nodes
|
|
53
|
+
to prevent jsdom from parsing the entire cascading style
|
|
54
|
+
sheet. Which is error prune and very resource intensive.
|
|
55
|
+
*/
|
|
56
|
+
var styleContents = [];
|
|
57
|
+
data.html = data.html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style[^>]*>)/gi, function (match, startTag, content, endTag) {
|
|
58
|
+
styleContents.push(content);
|
|
59
|
+
return "".concat(startTag).concat(endTag);
|
|
60
|
+
});
|
|
61
|
+
var dom;
|
|
62
|
+
try {
|
|
63
|
+
/*
|
|
64
|
+
NOTE: We have to translate template delimiter to html
|
|
65
|
+
compatible sequences and translate it back later to
|
|
66
|
+
avoid unexpected escape sequences in resulting html.
|
|
67
|
+
*/
|
|
68
|
+
dom = new _jsdom.JSDOM(data.html.replace(/<%/g, '##+#+#+##').replace(/%>/g, '##-#-#-##'));
|
|
69
|
+
} catch (error) {
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
var linkables = {
|
|
73
|
+
link: 'href',
|
|
74
|
+
script: 'src'
|
|
75
|
+
};
|
|
76
|
+
for (var _i = 0, _Object$entries = Object.entries(linkables); _i < _Object$entries.length; _i++) {
|
|
77
|
+
var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2),
|
|
78
|
+
tagName = _Object$entries$_i[0],
|
|
79
|
+
attributeName = _Object$entries$_i[1];
|
|
80
|
+
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++) {
|
|
81
|
+
var domNode = _Array$from[_i2];
|
|
82
|
+
/*
|
|
83
|
+
NOTE: Removing symbols after a "&" in hash
|
|
84
|
+
string is necessary to match the generated
|
|
85
|
+
request strings in offline plugin.
|
|
86
|
+
*/
|
|
87
|
+
domNode.setAttribute(attributeName, domNode.getAttribute(attributeName).replace(new RegExp('(\\?' + "".concat(_this.options.hashAlgorithm, "=") + '[^&]+).*$'), '$1'));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/*
|
|
91
|
+
NOTE: We have to restore template delimiter and style
|
|
92
|
+
contents.
|
|
93
|
+
*/
|
|
94
|
+
data.html = dom.serialize().replace(/##\+#\+#\+##/g, '<%').replace(/##-#-#-##/g, '%>').replace(/(<style[^>]*>)[\s\S]*?(<\/style[^>]*>)/gi, function (match, startTag, endTag) {
|
|
95
|
+
return "".concat(startTag).concat(styleContents.shift()) + endTag;
|
|
96
|
+
});
|
|
97
|
+
// region post compilation
|
|
98
|
+
var _iterator = _createForOfIteratorHelper(_this.options.files),
|
|
99
|
+
_step;
|
|
100
|
+
try {
|
|
101
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
102
|
+
var htmlFileSpecification = _step.value;
|
|
103
|
+
if (htmlFileSpecification.filename === data.plugin.options.filename) {
|
|
104
|
+
var _iterator2 = _createForOfIteratorHelper([].concat(htmlFileSpecification.template.use)),
|
|
105
|
+
_step2;
|
|
106
|
+
try {
|
|
107
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
108
|
+
var _loaderConfiguration$;
|
|
109
|
+
var loaderConfiguration = _step2.value;
|
|
110
|
+
if ((_loaderConfiguration$ = loaderConfiguration.options) !== null && _loaderConfiguration$ !== void 0 && _loaderConfiguration$.compileSteps && typeof loaderConfiguration.options.compileSteps === 'number') data.html = _ejsLoader["default"].bind({
|
|
111
|
+
query: _clientnode["default"].extend(true, _clientnode["default"].copy(loaderConfiguration.options) || {}, htmlFileSpecification.template.postCompileOptions)
|
|
112
|
+
})(data.html);
|
|
113
|
+
}
|
|
114
|
+
} catch (err) {
|
|
115
|
+
_iterator2.e(err);
|
|
116
|
+
} finally {
|
|
117
|
+
_iterator2.f();
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// endregion
|
|
123
|
+
} catch (err) {
|
|
124
|
+
_iterator.e(err);
|
|
125
|
+
} finally {
|
|
126
|
+
_iterator.f();
|
|
127
|
+
}
|
|
128
|
+
return data;
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}]);
|
|
133
|
+
return HTMLTransformation;
|
|
134
|
+
}();
|
|
135
|
+
var _default = exports["default"] = HTMLTransformation;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
import { InPlaceAssetsIntoHTMLOptions } from '../type';
|
|
3
|
+
export declare class InPlaceAssetsIntoHTML {
|
|
4
|
+
private defaultOptions;
|
|
5
|
+
private options;
|
|
6
|
+
constructor(options?: Partial<InPlaceAssetsIntoHTMLOptions>);
|
|
7
|
+
apply(compiler: Compiler): void;
|
|
8
|
+
}
|
|
9
|
+
export default InPlaceAssetsIntoHTML;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// #!/usr/bin/env babel-node
|
|
2
|
+
// -*- coding: utf-8 -*-
|
|
3
|
+
/** @module InPlaceAssetsIntoHTML */
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/* !
|
|
7
|
+
region header
|
|
8
|
+
Copyright Torben Sickert (info["~at~"]torben.website) 16.12.2012
|
|
9
|
+
|
|
10
|
+
License
|
|
11
|
+
-------
|
|
12
|
+
|
|
13
|
+
This library written by Torben Sickert stand under a creative commons
|
|
14
|
+
naming 3.0 unported license.
|
|
15
|
+
See https://creativecommons.org/licenses/by/3.0/deed.de
|
|
16
|
+
endregion
|
|
17
|
+
*/
|
|
18
|
+
// region imports
|
|
19
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
20
|
+
Object.defineProperty(exports, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
});
|
|
23
|
+
exports["default"] = exports.InPlaceAssetsIntoHTML = void 0;
|
|
24
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
25
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
26
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
|
+
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; }
|
|
28
|
+
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; }
|
|
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
|
+
(0, _defineProperty2["default"])(this, "options", void 0);
|
|
36
|
+
this.options = _objectSpread(_objectSpread({}, this.defaultOptions), options);
|
|
37
|
+
}
|
|
38
|
+
(0, _createClass2["default"])(InPlaceAssetsIntoHTML, [{
|
|
39
|
+
key: "apply",
|
|
40
|
+
value: function apply(compiler) {
|
|
41
|
+
var _this = this;
|
|
42
|
+
var publicPath = compiler.options.output.publicPath || '';
|
|
43
|
+
if (publicPath && !publicPath.endsWith('/')) publicPath += '/';
|
|
44
|
+
compiler.hooks.compilation.tap('inPlaceHTMLAssets', function (compilation) {
|
|
45
|
+
var hooks = _this.options.htmlPlugin.getHooks(compilation);
|
|
46
|
+
var inPlacedAssetNames = [];
|
|
47
|
+
hooks.alterAssetTagGroups.tap('inPlaceHTMLAssets', function (assets) {
|
|
48
|
+
var inPlace = function inPlace(type, tag) {
|
|
49
|
+
var settings;
|
|
50
|
+
var url = false;
|
|
51
|
+
if (tag.tagName === 'script') {
|
|
52
|
+
settings = _this.options.javaScript;
|
|
53
|
+
url = tag.attributes.src;
|
|
54
|
+
} else if (tag.tagName === 'style') {
|
|
55
|
+
settings = _this.options.cascadingStyleSheet;
|
|
56
|
+
url = tag.attributes.href;
|
|
57
|
+
}
|
|
58
|
+
if (!(url && typeof url === 'string')) return tag;
|
|
59
|
+
var name = publicPath ? url.replace(publicPath, '') : url;
|
|
60
|
+
if (compilation.assets[name] && settings[type] && [].concat(settings[type]).some(function (pattern) {
|
|
61
|
+
return new RegExp(pattern).test(name);
|
|
62
|
+
})) {
|
|
63
|
+
var newAttributes = _objectSpread({}, tag.attributes);
|
|
64
|
+
delete newAttributes.href;
|
|
65
|
+
delete newAttributes.src;
|
|
66
|
+
inPlacedAssetNames.push(name);
|
|
67
|
+
return _objectSpread(_objectSpread({}, tag), {}, {
|
|
68
|
+
attributes: newAttributes,
|
|
69
|
+
innerHTML: compilation.assets[name].source(),
|
|
70
|
+
tagName: 'script'
|
|
71
|
+
});
|
|
72
|
+
}
|
|
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;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// NOTE: Avoid if you still want to emit the runtime chunks:
|
|
81
|
+
hooks.afterEmit.tap('inPlaceHTMLAssets', function (asset) {
|
|
82
|
+
for (var _i = 0, _inPlacedAssetNames = inPlacedAssetNames; _i < _inPlacedAssetNames.length; _i++) {
|
|
83
|
+
var name = _inPlacedAssetNames[_i];
|
|
84
|
+
delete compilation.assets[name];
|
|
85
|
+
}
|
|
86
|
+
return asset;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}]);
|
|
91
|
+
return InPlaceAssetsIntoHTML;
|
|
92
|
+
}();
|
|
93
|
+
var _default = exports["default"] = InPlaceAssetsIntoHTML;
|