@caweb/html-webpack-plugin 2.1.4 → 2.1.6
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/CHANGELOG.md +7 -0
- package/index.js +56 -81
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@ const templatePath = path.join( 'node_modules', '@caweb', 'template');
|
|
|
26
26
|
const iconLibraryPath = path.join( 'node_modules', '@caweb', 'icon-library');
|
|
27
27
|
|
|
28
28
|
const allowedAssetExts = [
|
|
29
|
+
'.js', '.css',
|
|
29
30
|
'.png', '.jpg', '.jpeg', '.gif', '.svg',
|
|
30
31
|
'.bmp', '.gif', '.ico',
|
|
31
32
|
'.woff', '.woff2', '.eot', '.ttf', '.otf'
|
|
@@ -33,38 +34,19 @@ const allowedAssetExts = [
|
|
|
33
34
|
|
|
34
35
|
// function to process assets from regex matches
|
|
35
36
|
const processAssets = ( assets = [] , type = 'style') => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if( 'style' === type ){
|
|
43
|
-
temp = assets
|
|
44
|
-
.map( a => {
|
|
45
|
-
return a
|
|
46
|
-
.replace(/(style=".*url\(\s*)(\S+)\s*\)/g, '$2') // get url() content
|
|
47
|
-
.replace(/((src|href)=")(\S+)".*/g, '$3') // remove src=" or href="
|
|
48
|
-
// .replace(/['"]/g, '') // remove quotes
|
|
49
|
-
})
|
|
50
|
-
} else {
|
|
51
|
-
temp = assets // map to extract just the asset file
|
|
52
|
-
.map( a => {
|
|
53
|
-
return a
|
|
54
|
-
.replace(/((src|href)=")/g, '') // remove src=" or href="
|
|
55
|
-
// .replace(/".*/g, '') // remove anything after the first "
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return temp
|
|
60
|
-
// filter to only include local files with allowed extensions
|
|
61
|
-
.filter( asset => {
|
|
37
|
+
return assets.map( asset => {
|
|
38
|
+
return asset
|
|
39
|
+
.replace(/[\w]+="/, '') // remove src=" or href=" or style="
|
|
40
|
+
.replace(/"$/, '') // remove trailing "
|
|
41
|
+
})
|
|
42
|
+
.filter( asset => {
|
|
62
43
|
let ext = path.extname( asset ).toLowerCase();
|
|
63
44
|
let localFile = fs.existsSync( path.join( appPath, asset ) )
|
|
64
45
|
|
|
65
46
|
return localFile && allowedAssetExts.includes( ext );
|
|
66
47
|
|
|
67
|
-
|
|
48
|
+
})
|
|
49
|
+
|
|
68
50
|
}
|
|
69
51
|
|
|
70
52
|
const pluginName = 'CAWebHTMLPlugin';
|
|
@@ -212,31 +194,24 @@ class CAWebHTMLPlugin extends HtmlWebpackPlugin{
|
|
|
212
194
|
pluginName,
|
|
213
195
|
({html, outputName, plugin}, cb) => {
|
|
214
196
|
// if the html contains local assets those assets are added to the options.assets array
|
|
215
|
-
|
|
216
|
-
let srcHrefAssets = processAssets(html.match(/(src|href)="(.+)"/g));
|
|
217
|
-
let styleAssets = processAssets(html.match(/style=".*url\((\S+)\)/g));
|
|
218
|
-
let allAssets = [ ...new Set([
|
|
219
|
-
...srcHrefAssets,
|
|
220
|
-
...styleAssets
|
|
221
|
-
])
|
|
222
|
-
];
|
|
197
|
+
let allAssets = processAssets(html.match(/(src|href|style)="(.+?)"/g));
|
|
223
198
|
|
|
224
199
|
allAssets.forEach( asset =>{
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
fs.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
){
|
|
236
|
-
this.options.assets.push(localFile);
|
|
237
|
-
}
|
|
200
|
+
// we add the asset to the compilation file dependencies so webpack watches it for changes
|
|
201
|
+
// compilation.fileDependencies.add( path.join( appPath, asset ) );
|
|
202
|
+
|
|
203
|
+
compilation.emitAsset(
|
|
204
|
+
// we remove the appPath from the asset path
|
|
205
|
+
// we remove the node_modules/@ from the asset path
|
|
206
|
+
asset.replace(appPath, '').replace(/[\\\/]?node_modules[\\\/@]+/g, ''),
|
|
207
|
+
new compiler.webpack.sources.RawSource( fs.readFileSync(path.join( appPath, asset ) ) )
|
|
208
|
+
);
|
|
209
|
+
|
|
238
210
|
});
|
|
239
211
|
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
// compilation.fileDependencies.add( allAssets[0] );
|
|
240
215
|
// Tell webpack to move on
|
|
241
216
|
cb(null, {html, outputName, plugin});
|
|
242
217
|
},
|
|
@@ -245,43 +220,43 @@ class CAWebHTMLPlugin extends HtmlWebpackPlugin{
|
|
|
245
220
|
HtmlWebpackPlugin.getCompilationHooks(compilation).afterEmit.tapAsync(
|
|
246
221
|
pluginName,
|
|
247
222
|
({outputName, plugin}, cb) => {
|
|
248
|
-
|
|
249
223
|
// if there are any assets in the options.assets array
|
|
250
224
|
// we add them to the compilation and emit them
|
|
251
225
|
this.options.assets.forEach( async (asset) => {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
// we remove the
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
226
|
+
// console.log( asset );
|
|
227
|
+
// compilation.fileDependencies.add( asset );
|
|
228
|
+
|
|
229
|
+
// // we remove the appPath from the asset path
|
|
230
|
+
// // we remove the node_modules/@ from the asset path
|
|
231
|
+
// compilation.emitAsset(
|
|
232
|
+
// asset.replace(appPath, '').replace(/[\\\/]?node_modules[\\\/@]+/g, ''),
|
|
233
|
+
// new compiler.webpack.sources.RawSource( fs.readFileSync(asset) )
|
|
234
|
+
// );
|
|
235
|
+
|
|
236
|
+
// // if the asset is the @caweb/icon-library font-only.css file we have to also add the font files
|
|
237
|
+
// if( asset.match(/@caweb\/icon-library\/build\/font-only-?.*.css/g) ){
|
|
238
|
+
// let fontPath = path.join( iconLibraryPath, 'build', 'fonts' );
|
|
239
|
+
|
|
240
|
+
// let fontFiles = fs.readdirSync(fontPath).filter( (file) => {
|
|
241
|
+
// return file.endsWith('.woff') ||
|
|
242
|
+
// file.endsWith('.woff2') ||
|
|
243
|
+
// file.endsWith('.eot') ||
|
|
244
|
+
// file.endsWith('.svg') ||
|
|
245
|
+
// file.endsWith('.ttf');
|
|
246
|
+
// });
|
|
247
|
+
|
|
248
|
+
// fontFiles.forEach( (file) => {
|
|
249
|
+
// compilation.fileDependencies.add( file );
|
|
250
|
+
|
|
251
|
+
// let filePath = path.join( fontPath, file );
|
|
277
252
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
253
|
+
// // we remove the appPath from the asset path
|
|
254
|
+
// compilation.emitAsset(
|
|
255
|
+
// filePath.replace(appPath, '').replace(/[\\\/]?node_modules[\\\/@]+/g, ''),
|
|
256
|
+
// new compiler.webpack.sources.RawSource( fs.readFileSync(filePath) )
|
|
257
|
+
// );
|
|
258
|
+
// });
|
|
259
|
+
// }
|
|
285
260
|
});
|
|
286
261
|
|
|
287
262
|
// Tell webpack to move on
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caweb/html-webpack-plugin",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "CAWebPublishing Site Generation HTML Webpack Plugin",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@caweb/framework": "^1.9.
|
|
28
|
+
"@caweb/framework": "^1.9.9",
|
|
29
29
|
"@caweb/icon-library": "^1.1.7",
|
|
30
|
-
"@caweb/template": "^1.0.
|
|
30
|
+
"@caweb/template": "^1.0.16",
|
|
31
31
|
"html-webpack-plugin": "^5.6.6"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"test": "echo \"Error: run tests from root\" && exit 0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"webpack": "^5.105.
|
|
40
|
+
"webpack": "^5.105.2",
|
|
41
41
|
"webpack-cli": "^6.0.1"
|
|
42
42
|
}
|
|
43
43
|
}
|