weboptimizer 2.0.1170 → 2.0.1174
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.d.ts +1 -0
- package/browser.js +38 -15
- package/package.json +1 -6
- package/readme.md +108 -113
package/browser.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const browser: Browser;
|
|
|
4
4
|
* Provides a generic browser api in node or web contexts.
|
|
5
5
|
* @param replaceWindow - Indicates whether a potential existing window object
|
|
6
6
|
* should be replaced or not.
|
|
7
|
+
*
|
|
7
8
|
* @returns Determined environment.
|
|
8
9
|
*/
|
|
9
10
|
export declare const getInitializedBrowser: (replaceWindow?: boolean) => Promise<InitializedBrowser>;
|
package/browser.js
CHANGED
|
@@ -44,8 +44,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
44
44
|
|
|
45
45
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
//
|
|
47
|
+
// endregion
|
|
48
|
+
// region variables
|
|
49
49
|
var onCreatedListener = [];
|
|
50
50
|
var browser = {
|
|
51
51
|
debug: false,
|
|
@@ -108,9 +108,31 @@ if (typeof TARGET_TECHNOLOGY === 'undefined' || TARGET_TECHNOLOGY === 'node')
|
|
|
108
108
|
browser.initialized = true;
|
|
109
109
|
browser.instance = new browser.DOM(template, {
|
|
110
110
|
beforeParse: function beforeParse(window) {
|
|
111
|
+
var _global$window;
|
|
112
|
+
|
|
111
113
|
// We want to use it in a polymorphic way.
|
|
112
|
-
browser.window = window;
|
|
114
|
+
browser.window = (_global$window = global.window) !== null && _global$window !== void 0 ? _global$window : window;
|
|
113
115
|
window.document.addEventListener('DOMContentLoaded', function () {
|
|
116
|
+
/*
|
|
117
|
+
Move template results into global
|
|
118
|
+
pre-defined dom.
|
|
119
|
+
*/
|
|
120
|
+
if (global.window) {
|
|
121
|
+
var _iterator2 = _createForOfIteratorHelper(['head', 'body']),
|
|
122
|
+
_step2;
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
126
|
+
var type = _step2.value;
|
|
127
|
+
global.window.document[type].innerHTML = window.document[type].innerHTML;
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
_iterator2.e(err);
|
|
131
|
+
} finally {
|
|
132
|
+
_iterator2.f();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
114
136
|
browser.domContentLoaded = true;
|
|
115
137
|
});
|
|
116
138
|
window.addEventListener('load', function () {
|
|
@@ -121,18 +143,18 @@ if (typeof TARGET_TECHNOLOGY === 'undefined' || TARGET_TECHNOLOGY === 'node')
|
|
|
121
143
|
browser.domContentLoaded = browser.windowLoaded = true;
|
|
122
144
|
});
|
|
123
145
|
|
|
124
|
-
var
|
|
125
|
-
|
|
146
|
+
var _iterator3 = _createForOfIteratorHelper(onCreatedListener),
|
|
147
|
+
_step3;
|
|
126
148
|
|
|
127
149
|
try {
|
|
128
|
-
for (
|
|
129
|
-
var callback =
|
|
150
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
151
|
+
var callback = _step3.value;
|
|
130
152
|
callback();
|
|
131
153
|
}
|
|
132
154
|
} catch (err) {
|
|
133
|
-
|
|
155
|
+
_iterator3.e(err);
|
|
134
156
|
} finally {
|
|
135
|
-
|
|
157
|
+
_iterator3.f();
|
|
136
158
|
}
|
|
137
159
|
},
|
|
138
160
|
resources: 'usable',
|
|
@@ -206,18 +228,18 @@ if (typeof TARGET_TECHNOLOGY === 'undefined' || TARGET_TECHNOLOGY === 'node')
|
|
|
206
228
|
browser.windowLoaded = true;
|
|
207
229
|
});
|
|
208
230
|
void _clientnode["default"].timeout(function () {
|
|
209
|
-
var
|
|
210
|
-
|
|
231
|
+
var _iterator4 = _createForOfIteratorHelper(onCreatedListener),
|
|
232
|
+
_step4;
|
|
211
233
|
|
|
212
234
|
try {
|
|
213
|
-
for (
|
|
214
|
-
var callback =
|
|
235
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
236
|
+
var callback = _step4.value;
|
|
215
237
|
callback();
|
|
216
238
|
}
|
|
217
239
|
} catch (err) {
|
|
218
|
-
|
|
240
|
+
_iterator4.e(err);
|
|
219
241
|
} finally {
|
|
220
|
-
|
|
242
|
+
_iterator4.f();
|
|
221
243
|
}
|
|
222
244
|
});
|
|
223
245
|
} // endregion
|
|
@@ -226,6 +248,7 @@ if (typeof TARGET_TECHNOLOGY === 'undefined' || TARGET_TECHNOLOGY === 'node')
|
|
|
226
248
|
* Provides a generic browser api in node or web contexts.
|
|
227
249
|
* @param replaceWindow - Indicates whether a potential existing window object
|
|
228
250
|
* should be replaced or not.
|
|
251
|
+
*
|
|
229
252
|
* @returns Determined environment.
|
|
230
253
|
*/
|
|
231
254
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weboptimizer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1174",
|
|
4
4
|
"description": "A generic web optimizer, (module) bundler and development environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -116,7 +116,6 @@
|
|
|
116
116
|
"@types/html-minifier": "*",
|
|
117
117
|
"@types/html-minifier-terser": "*",
|
|
118
118
|
"@types/imagemin": "*",
|
|
119
|
-
"@types/jest": "*",
|
|
120
119
|
"@types/node": "*",
|
|
121
120
|
"@types/postcss-import": "*",
|
|
122
121
|
"@types/postcss-url": "*",
|
|
@@ -160,7 +159,6 @@
|
|
|
160
159
|
"@types/favicons": "*",
|
|
161
160
|
"@types/html-minifier": "*",
|
|
162
161
|
"@types/imagemin": "*",
|
|
163
|
-
"@types/jest": "*",
|
|
164
162
|
"@types/node": "*",
|
|
165
163
|
"@types/webpack-env": "*",
|
|
166
164
|
"@typescript-eslint/eslint-plugin": "*",
|
|
@@ -207,9 +205,6 @@
|
|
|
207
205
|
"@types/html-minifier": {
|
|
208
206
|
"optional": true
|
|
209
207
|
},
|
|
210
|
-
"@types/jest": {
|
|
211
|
-
"optional": true
|
|
212
|
-
},
|
|
213
208
|
"@types/node": {
|
|
214
209
|
"optional": true
|
|
215
210
|
},
|
package/readme.md
CHANGED
|
@@ -99,15 +99,15 @@ Installation
|
|
|
99
99
|
|
|
100
100
|
Edit your **package.json** to add **one** dependency:
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
```JSON
|
|
103
|
+
...
|
|
104
|
+
"dependencies": {
|
|
104
105
|
...
|
|
105
|
-
"
|
|
106
|
-
...
|
|
107
|
-
"weboptimizer": "latest",
|
|
108
|
-
...
|
|
109
|
-
},
|
|
106
|
+
"weboptimizer": "latest",
|
|
110
107
|
...
|
|
108
|
+
},
|
|
109
|
+
...
|
|
110
|
+
```
|
|
111
111
|
|
|
112
112
|
Update your **packages** via npm and have fun:
|
|
113
113
|
|
|
@@ -120,79 +120,79 @@ First you should specify some tasks/use-cases you want to use in you project.
|
|
|
120
120
|
You can do this in your **package.json**. All supported scripts and some useful
|
|
121
121
|
compositions are listed below:
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
```JSON
|
|
124
|
+
...
|
|
125
|
+
"scripts": {
|
|
125
126
|
...
|
|
126
|
-
"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"test:browser": "weboptimizer test:browser",
|
|
141
|
-
"watch": "weboptimizer build --watch",
|
|
142
|
-
...
|
|
143
|
-
},
|
|
127
|
+
"build": "weboptimizer build",
|
|
128
|
+
"build:stats": "weboptimizer build --profile --json >/tmp/stat.json && echo 'Results successfully written to \"/tmp/stat.json\".'",
|
|
129
|
+
"check": "yarn check:types; yarn lint",
|
|
130
|
+
"check:types": "weboptimizer check:types",
|
|
131
|
+
"clear": "weboptimizer clear",
|
|
132
|
+
"document": "weboptimizer document",
|
|
133
|
+
"lint": "weboptimizer lint",
|
|
134
|
+
"postinstall": "weboptimizer build",
|
|
135
|
+
"preinstall": "weboptimizer preinstall",
|
|
136
|
+
"serve": "weboptimizer serve",
|
|
137
|
+
"start": "npm run serve",
|
|
138
|
+
"test": "weboptimizer test",
|
|
139
|
+
"test:browser": "weboptimizer test:browser",
|
|
140
|
+
"watch": "weboptimizer build --watch",
|
|
144
141
|
...
|
|
142
|
+
},
|
|
143
|
+
...
|
|
144
|
+
```
|
|
145
145
|
|
|
146
146
|
You can easily run any specified script via npm's command lint interface:
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
```bash
|
|
149
|
+
npm run build -debug
|
|
150
|
+
npm run lint
|
|
151
|
+
npm run watch -debug
|
|
152
|
+
npm run serve
|
|
153
|
+
...
|
|
154
|
+
```
|
|
155
155
|
|
|
156
156
|
If you want to configure your application to change any of the expected
|
|
157
157
|
default source, target, asset or build paths do it in your **package.json**:
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
```JSON
|
|
160
|
+
...
|
|
161
|
+
"webOptimizer": {
|
|
161
162
|
...
|
|
162
|
-
"
|
|
163
|
+
"path": {
|
|
163
164
|
...
|
|
164
|
-
"
|
|
165
|
+
"apiDocumentation": "apiDocumentation/",
|
|
166
|
+
"source": {
|
|
165
167
|
...
|
|
166
|
-
"
|
|
167
|
-
"source": {
|
|
168
|
-
...
|
|
169
|
-
"asset": {
|
|
170
|
-
...
|
|
171
|
-
"cascadingStyleSheet": "cascadingStyleSheet/",
|
|
172
|
-
"data": "data/",
|
|
173
|
-
"favicon": "favicon.png",
|
|
174
|
-
"font": "font/",
|
|
175
|
-
"image": "image/",
|
|
176
|
-
"javaScript": "javaScript/",
|
|
177
|
-
"publicTarget": "",
|
|
178
|
-
"template": "template/"
|
|
179
|
-
..
|
|
180
|
-
},
|
|
168
|
+
"asset": {
|
|
181
169
|
...
|
|
170
|
+
"cascadingStyleSheet": "cascadingStyleSheet/",
|
|
171
|
+
"data": "data/",
|
|
172
|
+
"favicon": "favicon.png",
|
|
173
|
+
"font": "font/",
|
|
174
|
+
"image": "image/",
|
|
175
|
+
"javaScript": "javaScript/",
|
|
176
|
+
"publicTarget": "",
|
|
177
|
+
"template": "template/"
|
|
178
|
+
..
|
|
182
179
|
},
|
|
183
|
-
"ignore": ["node_modules", ".git"],
|
|
184
|
-
"manifest": "manifest.appcache",
|
|
185
|
-
"target": {
|
|
186
|
-
...
|
|
187
|
-
"base": "build/",
|
|
188
|
-
...
|
|
189
|
-
},
|
|
190
|
-
"tidyUp": ["crap"],
|
|
191
180
|
...
|
|
192
181
|
},
|
|
182
|
+
"ignore": ["node_modules", ".git"],
|
|
183
|
+
"manifest": "manifest.appcache",
|
|
184
|
+
"target": {
|
|
185
|
+
...
|
|
186
|
+
"base": "build/",
|
|
187
|
+
...
|
|
188
|
+
},
|
|
189
|
+
"tidyUp": ["crap"],
|
|
193
190
|
...
|
|
194
191
|
},
|
|
195
192
|
...
|
|
193
|
+
},
|
|
194
|
+
...
|
|
195
|
+
```
|
|
196
196
|
|
|
197
197
|
It's recommended to first specify if you're writing a library (preserve
|
|
198
198
|
external dependencies not managed within current project) or an application
|
|
@@ -200,75 +200,71 @@ external dependencies not managed within current project) or an application
|
|
|
200
200
|
preconfigurations are targeting on this two different use cases. Anyway you can
|
|
201
201
|
customize each configuration preset by hand.
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
```JSON
|
|
204
|
+
...
|
|
205
|
+
"webOptimizer": {
|
|
205
206
|
...
|
|
206
|
-
"
|
|
207
|
-
...
|
|
208
|
-
"library": false,
|
|
209
|
-
...
|
|
210
|
-
},
|
|
207
|
+
"library": false,
|
|
211
208
|
...
|
|
209
|
+
},
|
|
210
|
+
...
|
|
211
|
+
```
|
|
212
212
|
|
|
213
213
|
You can even reference any value or evaluate any configuration value
|
|
214
214
|
dynamically though a complete javaScript compatible evaluation mechanism:
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
```JSON
|
|
217
|
+
...
|
|
218
|
+
"webOptimizer": {
|
|
219
219
|
...
|
|
220
|
-
"
|
|
220
|
+
"path": {
|
|
221
221
|
...
|
|
222
|
-
"
|
|
222
|
+
"source": {
|
|
223
223
|
...
|
|
224
|
-
"
|
|
224
|
+
"base": "/",
|
|
225
|
+
"asset": {
|
|
225
226
|
...
|
|
226
|
-
"
|
|
227
|
-
"
|
|
228
|
-
|
|
229
|
-
"cascadingStyleSheet": "cascadingStyleSheet/",
|
|
230
|
-
"template": {
|
|
231
|
-
"__evaluate__": "self.debug ? '' : self.path.source.base"
|
|
232
|
-
},
|
|
233
|
-
...
|
|
227
|
+
"cascadingStyleSheet": "cascadingStyleSheet/",
|
|
228
|
+
"template": {
|
|
229
|
+
"__evaluate__": "self.debug ? '' : self.path.source.base"
|
|
234
230
|
},
|
|
235
231
|
...
|
|
236
232
|
},
|
|
237
233
|
...
|
|
238
234
|
},
|
|
239
235
|
...
|
|
240
|
-
|
|
236
|
+
},
|
|
237
|
+
...
|
|
238
|
+
"offline": {
|
|
239
|
+
...
|
|
240
|
+
"externals": [
|
|
241
241
|
...
|
|
242
|
-
"
|
|
243
|
-
|
|
244
|
-
{"__evaluate__": "self.path.source.asset.cascadingStyleSheet"},
|
|
245
|
-
"onlineAvailable.txt",
|
|
246
|
-
...
|
|
247
|
-
],
|
|
242
|
+
{"__evaluate__": "self.path.source.asset.cascadingStyleSheet"},
|
|
243
|
+
"onlineAvailable.txt",
|
|
248
244
|
...
|
|
249
|
-
|
|
245
|
+
],
|
|
250
246
|
...
|
|
251
247
|
},
|
|
252
248
|
...
|
|
249
|
+
},
|
|
250
|
+
...
|
|
251
|
+
```
|
|
253
252
|
|
|
254
253
|
You can even execute scripts to determine a value:
|
|
255
254
|
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
``JSON
|
|
256
|
+
...
|
|
257
|
+
"webOptimizer": {
|
|
258
258
|
...
|
|
259
|
-
"
|
|
259
|
+
"path": {
|
|
260
260
|
...
|
|
261
|
-
"
|
|
261
|
+
"source": {
|
|
262
262
|
...
|
|
263
|
-
"
|
|
263
|
+
"base": "/",
|
|
264
|
+
"asset": {
|
|
264
265
|
...
|
|
265
|
-
"
|
|
266
|
-
|
|
267
|
-
...
|
|
268
|
-
"template": {
|
|
269
|
-
"__execute__": "test = self.path.source.base; if (test.endsWith('js')) return 'bar/';return 'foo/'"
|
|
270
|
-
},
|
|
271
|
-
...
|
|
266
|
+
"template": {
|
|
267
|
+
"__execute__": "test = self.path.source.base; if (test.endsWith('js')) return 'bar/';return 'foo/'"
|
|
272
268
|
},
|
|
273
269
|
...
|
|
274
270
|
},
|
|
@@ -277,6 +273,9 @@ You can even execute scripts to determine a value:
|
|
|
277
273
|
...
|
|
278
274
|
},
|
|
279
275
|
...
|
|
276
|
+
},
|
|
277
|
+
...
|
|
278
|
+
```
|
|
280
279
|
|
|
281
280
|
For all available configuration possibilities please have a look at the
|
|
282
281
|
**package.json** file in this project since these values will be extended on
|
|
@@ -287,16 +286,12 @@ complete generic command line interface: The last argument should evaluate to
|
|
|
287
286
|
a javaScript object which will be used as source for extending the default
|
|
288
287
|
behavior. Any javaScript will be supported:
|
|
289
288
|
|
|
290
|
-
#!JSON
|
|
291
|
-
|
|
292
289
|
npm run build '{module:{preprocessor:{javaScript:{loader:"babel"}}}}'
|
|
293
290
|
|
|
294
291
|
If you're using weboptimizer in a toolchain were none printable or none unicode
|
|
295
292
|
compatible symbols should be used (for example content which should replace
|
|
296
293
|
placeholder) you can encode your javaScript expression as base64 code:
|
|
297
294
|
|
|
298
|
-
#!bash
|
|
299
|
-
|
|
300
295
|
npm run build '{module:{preprocessor:{ejs:{locals:{name:'häns'}}}}}'
|
|
301
296
|
|
|
302
297
|
# is the same as:
|
|
@@ -307,15 +302,15 @@ There is a static tool [clientnode](https://torben.website/clientNode) and
|
|
|
307
302
|
helper instance provided to each evaluation or execution context within the
|
|
308
303
|
package.json (see the API-Documentation, link above, for more details):
|
|
309
304
|
|
|
310
|
-
|
|
311
|
-
|
|
305
|
+
```JSON
|
|
306
|
+
...
|
|
307
|
+
"webOptimizer": {
|
|
312
308
|
...
|
|
313
|
-
"
|
|
314
|
-
...
|
|
315
|
-
"libraryName": {"__evaluate__": Tools.isPlainObject(self.name) ? helper.stripLoader(self.request) : 'random'},
|
|
316
|
-
...
|
|
317
|
-
},
|
|
309
|
+
"libraryName": {"__evaluate__": Tools.isPlainObject(self.name) ? helper.stripLoader(self.request) : 'random'},
|
|
318
310
|
...
|
|
311
|
+
},
|
|
312
|
+
...
|
|
313
|
+
```
|
|
319
314
|
|
|
320
315
|
<!-- region modline
|
|
321
316
|
vim: set tabstop=4 shiftwidth=4 expandtab:
|