weboptimizer 2.0.1168 → 2.0.1172

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/declarations.d.ts CHANGED
@@ -25,7 +25,12 @@ declare module 'postcss-fontpath' {
25
25
  declare module 'postcss-sprites' {
26
26
  export default function(options:Partial<{
27
27
  filterBy:() => Promise<void>
28
- hooks:{onSaveSpritesheet:(_image:Mapping) => string}
28
+ hooks:{
29
+ onSaveSpritesheet:(_image:Mapping<unknown>) => string
30
+ onUpdateRule:(
31
+ _rule:PostcssNode, _token:PostcssNode, _image:Mapping<unknown>
32
+ ) => void
33
+ }
29
34
  spritePath:string
30
35
  stylesheetPath:null|string
31
36
  verbose:boolean
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weboptimizer",
3
- "version": "2.0.1168",
3
+ "version": "2.0.1172",
4
4
  "description": "A generic web optimizer, (module) bundler and development environment.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -111,7 +111,6 @@
111
111
  "devDependencies": {
112
112
  "@babel/cli": "*",
113
113
  "@babel/eslint-parser": "*",
114
- "@types/cssnano": "*",
115
114
  "@types/ejs": "*",
116
115
  "@types/favicons": "*",
117
116
  "@types/html-minifier": "*",
@@ -923,10 +922,17 @@
923
922
  },
924
923
  "cssnano": {
925
924
  "#": "The autoprefixer has to be disabled in this context since it would remove all needed vendor prefixes from the preceding processing (every prefix should be needed here).",
926
- "autoprefixer": false,
927
- "discardUnused": {
928
- "__evaluate__": "!self.library"
929
- }
925
+ "preset": [
926
+ {
927
+ "__evaluate__": "optionalRequire('cssnano-preset-default')"
928
+ },
929
+ {
930
+ "autoprefixer": false,
931
+ "discardUnused": {
932
+ "__evaluate__": "!self.library"
933
+ }
934
+ }
935
+ ]
930
936
  },
931
937
  "data": {
932
938
  "exclude": null,
package/readme.md CHANGED
@@ -99,15 +99,15 @@ Installation
99
99
 
100
100
  Edit your **package.json** to add **one** dependency:
101
101
 
102
- #!JSON
103
-
102
+ ```JSON
103
+ ...
104
+ "dependencies": {
104
105
  ...
105
- "dependencies": {
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
- #!JSON
124
-
123
+ ```JSON
124
+ ...
125
+ "scripts": {
125
126
  ...
126
- "scripts": {
127
- ...
128
- "build": "weboptimizer build",
129
- "build:stats": "weboptimizer build --profile --json >/tmp/stat.json && echo 'Results successfully written to \"/tmp/stat.json\".'",
130
- "check": "yarn check:types; yarn lint",
131
- "check:types": "weboptimizer check:types",
132
- "clear": "weboptimizer clear",
133
- "document": "weboptimizer document",
134
- "lint": "weboptimizer lint",
135
- "postinstall": "weboptimizer build",
136
- "preinstall": "weboptimizer preinstall",
137
- "serve": "weboptimizer serve",
138
- "start": "npm run serve",
139
- "test": "weboptimizer test",
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
- #!bash
149
-
150
- npm run build -debug
151
- npm run lint
152
- npm run watch -debug
153
- npm run serve
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
- #!JSON
160
-
159
+ ```JSON
160
+ ...
161
+ "webOptimizer": {
161
162
  ...
162
- "webOptimizer": {
163
+ "path": {
163
164
  ...
164
- "path": {
165
+ "apiDocumentation": "apiDocumentation/",
166
+ "source": {
165
167
  ...
166
- "apiDocumentation": "apiDocumentation/",
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
- #!JSON
204
-
203
+ ```JSON
204
+ ...
205
+ "webOptimizer": {
205
206
  ...
206
- "webOptimizer": {
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
- #!JSON
218
-
216
+ ```JSON
217
+ ...
218
+ "webOptimizer": {
219
219
  ...
220
- "webOptimizer": {
220
+ "path": {
221
221
  ...
222
- "path": {
222
+ "source": {
223
223
  ...
224
- "source": {
224
+ "base": "/",
225
+ "asset": {
225
226
  ...
226
- "base": "/",
227
- "asset": {
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
- "offline": {
236
+ },
237
+ ...
238
+ "offline": {
239
+ ...
240
+ "externals": [
241
241
  ...
242
- "externals": [
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
- #!JSON
257
-
255
+ ``JSON
256
+ ...
257
+ "webOptimizer": {
258
258
  ...
259
- "webOptimizer": {
259
+ "path": {
260
260
  ...
261
- "path": {
261
+ "source": {
262
262
  ...
263
- "source": {
263
+ "base": "/",
264
+ "asset": {
264
265
  ...
265
- "base": "/",
266
- "asset": {
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
- #!JSON
311
-
305
+ ```JSON
306
+ ...
307
+ "webOptimizer": {
312
308
  ...
313
- "webOptimizer": {
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:
@@ -54,7 +54,8 @@ var _helper = _interopRequireDefault(require("./helper"));
54
54
 
55
55
  var _ejsLoader = _interopRequireDefault(require("./ejsLoader"));
56
56
 
57
- var _this = void 0,
57
+ var _optionalRequire,
58
+ _this = void 0,
58
59
  _configuration$path$c,
59
60
  _configuration$cache,
60
61
  _configuration$cache2,
@@ -78,6 +79,7 @@ var postcssCSSnano = (0, _clientnode.optionalRequire)('cssnano');
78
79
  var postcssFontpath = (0, _clientnode.optionalRequire)('postcss-fontpath');
79
80
  var postcssImport = (0, _clientnode.optionalRequire)('postcss-import');
80
81
  var postcssSprites = (0, _clientnode.optionalRequire)('postcss-sprites');
82
+ var updateRule = (_optionalRequire = (0, _clientnode.optionalRequire)('postcss-sprites/lib/core')) === null || _optionalRequire === void 0 ? void 0 : _optionalRequire.updateRule;
81
83
  var postcssURL = (0, _clientnode.optionalRequire)('postcss-url');
82
84
  var pluginNameResourceMapping = {
83
85
  HTML: 'html-webpack-plugin',
@@ -897,10 +899,20 @@ var cssUse = _module.preprocessor.cascadingStyleSheet.additional.pre.map(evaluat
897
899
  onSaveSpritesheet: function onSaveSpritesheet(image) {
898
900
  return (0, _path.join)(image.spritePath, (0, _path.relative)(configuration.path.target.asset.image, configuration.files.compose.image));
899
901
  },
900
- // TODO
901
- onUpdateRule: function onUpdateRule(rule, declaration, output) {
902
- console.log('u', declaration.value, declaration.text);
903
- return output;
902
+
903
+ /*
904
+ Reset this token due to a
905
+ sprite bug with
906
+ "background-image" declaration
907
+ which do not refer to an image
908
+ (e.g. linear gradient instead).
909
+ */
910
+ onUpdateRule: function onUpdateRule(rule, token, image) {
911
+ if (token.value.includes(token.text)) updateRule(rule, token, image);else token.cloneAfter({
912
+ type: 'decl',
913
+ prop: 'background-image',
914
+ value: token.value
915
+ });
904
916
  }
905
917
  },
906
918
  stylesheetPath: configuration.path.source.asset.cascadingStyleSheet,