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
Copy file name to clipboardExpand all lines: README.md
+17-7Lines changed: 17 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,12 @@ The available options are:
90
90
91
91
By default the assets will be included in all files. If files are defined, the assets will only be included in specified file globs (uses the [minimatch](https://github.com/isaacs/minimatch) package).
92
92
93
+
-`cssAssets`: `array`
94
+
95
+
Optional shortcut for adding css assets. An array of css asset objects.
96
+
97
+
See the cssAssets example below for the syntax of css asset object.
98
+
93
99
Example
94
100
-------
95
101
Using `HtmlWebpackIncludeAssetsPlugin` and `CopyWebpackPlugin` to include assets to `html-webpack-plugin` template :
@@ -300,7 +306,7 @@ plugins: [
300
306
]
301
307
```
302
308
303
-
Sepcifying `links`
309
+
Specifying `cssAssets` (a shortcut for specifying assets of type css)
304
310
305
311
```javascript
306
312
output: {
@@ -315,15 +321,19 @@ plugins: [
315
321
newHtmlWebpackIncludeAssetsPlugin({
316
322
assets: [],
317
323
append:true,
318
-
links: [
324
+
cssAssets: [
319
325
{
320
-
rel:'icon',
321
-
href:'asset/path'
326
+
href:'asset/path',
327
+
attributes: {
328
+
rel:'icon'
329
+
}
322
330
},
323
331
{
324
-
rel:'manifest',
325
332
href:'/absolute/asset/path',
326
-
asset:false
333
+
asset:false,
334
+
attributes: {
335
+
rel:'manifest'
336
+
}
327
337
}
328
338
]
329
339
})
@@ -340,4 +350,4 @@ Will append the following link elements into the index template html
340
350
</head>
341
351
```
342
352
343
-
Note that the second link's href was not prefixed with the webpack `publicPath` because `link.asset` was set to `false`.
353
+
Note that the second cssAsset's href was not prefixed with the webpack `publicPath` because `csAsset.asset` was set to `false`.
Copy file name to clipboardExpand all lines: index.js
+78-90Lines changed: 78 additions & 90 deletions
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ function extend (target, source) {
79
79
functionHtmlWebpackIncludeAssetsPlugin(options){
80
80
assert(isObject(options),'HtmlWebpackIncludeAssetsPlugin options are required');
81
81
varassets;
82
-
varlinks;
82
+
varcssAssets;
83
83
if(options.resolvePaths!==undefined){
84
84
assert(isBoolean(options.resolvePaths),'HtmlWebpackIncludeAssetsPlugin options should specify a resolvePaths that is a boolean');
85
85
}
@@ -89,16 +89,27 @@ function HtmlWebpackIncludeAssetsPlugin (options) {
89
89
assets=options.assets;
90
90
}
91
91
assert(isArray(assets),'HtmlWebpackIncludeAssetsPlugin options must have an assets key with an array or string value');
92
-
if(options.links!==undefined){
93
-
links=options.links;
94
-
assert(isArray(links),'HtmlWebpackIncludeAssetsPlugin options link key should be an array');
95
-
links.forEach(function(link){
96
-
assert(isObject(link),'HtmlWebpackIncludeAssetsPlugin options link key should be an array of objects');
97
-
assert(isString(link.href),'HtmlWebpackIncludeAssetsPlugin options link key should be an array of objects with string href');
98
-
assert(isString(link.rel),'HtmlWebpackIncludeAssetsPlugin options link key should be an array of objects with string rel');
99
-
});
92
+
if(options.cssAssets!==undefined){
93
+
cssAssets=options.cssAssets;
94
+
assert(isArray(cssAssets),'HtmlWebpackIncludeAssetsPlugin options cssAsset key should be an array');
95
+
if(isArray(cssAssets)){
96
+
cssAssets.forEach(function(cssAsset){
97
+
assert(isObject(cssAsset),'HtmlWebpackIncludeAssetsPlugin options cssAsset key should be an array of objects');
98
+
assert(isString(cssAsset.href),'HtmlWebpackIncludeAssetsPlugin options cssAsset key should be an array of objects with string href');
99
+
if(cssAsset.attributes!==undefined){
100
+
assert(isObject(cssAsset.attributes),'HtmlWebpackIncludeAssetsPlugin options cssAsset key should be an array of objects with undefined or object attributes');
101
+
}else{
102
+
cssAsset.attributes={};
103
+
}
104
+
if(cssAsset.asset!==undefined){
105
+
assert(isBoolean(cssAsset.asset),'HtmlWebpackIncludeAssetsPlugin options cssAsset key should be an array of objects with undefined or boolean asset');
106
+
}else{
107
+
cssAsset.asset=true;
108
+
}
109
+
});
110
+
}
100
111
}else{
101
-
links=[];
112
+
cssAssets=[];
102
113
}
103
114
varjsExtensions;
104
115
if(options.jsExtensions!==undefined){
@@ -170,9 +181,11 @@ function HtmlWebpackIncludeAssetsPlugin (options) {
170
181
}
171
182
if(asset.attributes!==undefined){
172
183
assert(isObject(asset.attributes),'HtmlWebpackIncludeAssetsPlugin options assets key array objects attributes property should be an object');
173
-
forOwn(asset.attributes,function(value){
174
-
assert(isString(value)||isBoolean(value),'HtmlWebpackIncludeAssetsPlugin options assets key array objects attributes property should be an object with string or boolean values');
175
-
});
184
+
if(isObject(asset.attributes)){
185
+
forOwn(asset.attributes,function(value){
186
+
assert(isString(value)||isBoolean(value),'HtmlWebpackIncludeAssetsPlugin options assets key array objects attributes property should be an object with string or boolean values');
187
+
});
188
+
}
176
189
}
177
190
}else{
178
191
assert(false,'HtmlWebpackIncludeAssetsPlugin options assets key array must contain only strings and objects ('+asset+')');
@@ -212,7 +225,7 @@ function HtmlWebpackIncludeAssetsPlugin (options) {
212
225
}
213
226
this.options={
214
227
assets: assets,
215
-
links: links,
228
+
cssAssets: cssAssets,
216
229
jsExtensions: jsExtensions,
217
230
cssExtensions: cssExtensions,
218
231
append: options.append,
@@ -247,6 +260,11 @@ HtmlWebpackIncludeAssetsPlugin.prototype.apply = function (compiler) {
0 commit comments