You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 20, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+42-20Lines changed: 42 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,7 +141,7 @@ It uses only one target: `html`, with a list of the concerned files. For example
141
141
By default, it will consider the directory where the looked-at file is located as the 'root' filesystem. Each relative path (for example to a javascript file) will be resolved from this path. Same goes for the absolute ones.
142
142
If you need to change the 'root' dir, use the `root` option (see below).
143
143
144
-
Note that `useminPrepare` and `usemin` tasks will both throw an error if a resource is not found.
144
+
Note that `useminPrepare` and `usemin` tasks will both throw an error if a resource is not found.
145
145
146
146
```js
147
147
useminPrepare: {
@@ -260,18 +260,23 @@ The given steps or post-processors may be specified as strings (for the default
260
260
### resolveSource
261
261
262
262
Type: 'function'
263
-
Default: `nil`
263
+
Default: `undefined`
264
264
265
265
This is an optional hook allowing applications to override how source urls
266
266
are resolved to filesystem paths. This function is called with the signature
267
-
`resolveSource(sourceUrl, fileDir, fileName, blockTarget, searchPath)`. It should
268
-
return the path to the source file, `null` to indicate the default resolution
269
-
rules should be used, or `false` to indicate the file cannot be resolved.
var m =sourceUrl.match(/^\/alt-static-url\/(.*)/);
286
-
if(m){
287
-
var source =path.join("alt-static-location", m[1]);
288
-
if(fs.existsSync(source)) { return source; }
289
+
var fs =require('fs');
290
+
var path =require('path');
291
+
292
+
var match =sourceUrl.match(/^\/alt-static-url\/(.*)/);
293
+
if (match) {
294
+
var source =path.join("alt-static-location", match[1]);
295
+
// return the override source path if found on filesystem
296
+
// else will default to null which means that resource will be search using
297
+
// default behavior
298
+
if (fs.existsSync(source)) {
299
+
return source;
300
+
}
301
+
/*
302
+
// You might be interested in return false if source cannot be resolved using the
303
+
// following code instead:
304
+
// it will return the overriden source path if resource found on filesystem
305
+
// or false if not found, meaning default behavior will not be used
306
+
return fs.existsSync(source) ? source : false;
307
+
*/
289
308
}
309
+
// returning null will match the default behavior for any url not matching
310
+
// the prefix `^/alt-static-url/`
290
311
returnnull;
291
312
}
292
313
}
293
314
}
294
315
```
295
316
296
-
* To replicate the default behavior:
317
+
* To replicate the default behavior, use the following version. It should be noted that this is only for illustration purpose, as the default behavior will be used if no `resolveSource` hook is provided, or if `resolveSource` fails to resolve the sourceUrl, hence returning null.
0 commit comments