@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.
Files changed (3) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/index.js +56 -81
  3. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ v2.1.6
2
+ - Fixed issue with the way additional assets were being emitted
3
+ - Updated npm packages
4
+
5
+ v2.1.5
6
+ - Updated npm packages
7
+
1
8
  v2.1.4
2
9
  - Reemitting src/href/styles assets
3
10
  - Added minimum-scale=1.0 to viewport
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
- let temp = [];
37
-
38
- if( ! assets ){
39
- return temp;
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
- // and the assets are added to the compilation afterEmit
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
- let localFile = asset.startsWith('/') || asset.startsWith('\\') ?
226
- path.join( appPath, asset ) :
227
- asset;
228
-
229
- // if the asset is a local file
230
- // if the asset is not already in the options.assets array
231
- if(
232
- fs.existsSync(localFile) &&
233
- fs.lstatSync(localFile).isFile() &&
234
- ! this.options.assets.includes(localFile)
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
- compilation.fileDependencies.add( asset );
253
-
254
- // we remove the appPath from the asset path
255
- // we remove the node_modules/@ from the asset path
256
- compilation.emitAsset(
257
- asset.replace(appPath, '').replace(/[\\\/]?node_modules[\\\/@]+/g, ''),
258
- new compiler.webpack.sources.RawSource( fs.readFileSync(asset) )
259
- );
260
-
261
- // if the asset is the @caweb/icon-library font-only.css file we have to also add the font files
262
- if( asset.match(/@caweb\/icon-library\/build\/font-only-?.*.css/g) ){
263
- let fontPath = path.join( iconLibraryPath, 'build', 'fonts' );
264
-
265
- let fontFiles = fs.readdirSync(fontPath).filter( (file) => {
266
- return file.endsWith('.woff') ||
267
- file.endsWith('.woff2') ||
268
- file.endsWith('.eot') ||
269
- file.endsWith('.svg') ||
270
- file.endsWith('.ttf');
271
- });
272
-
273
- fontFiles.forEach( (file) => {
274
- compilation.fileDependencies.add( file );
275
-
276
- let filePath = path.join( fontPath, file );
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
- // we remove the appPath from the asset path
279
- compilation.emitAsset(
280
- filePath.replace(appPath, '').replace(/[\\\/]?node_modules[\\\/@]+/g, ''),
281
- new compiler.webpack.sources.RawSource( fs.readFileSync(filePath) )
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.4",
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.8",
28
+ "@caweb/framework": "^1.9.9",
29
29
  "@caweb/icon-library": "^1.1.7",
30
- "@caweb/template": "^1.0.14",
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.1",
40
+ "webpack": "^5.105.2",
41
41
  "webpack-cli": "^6.0.1"
42
42
  }
43
43
  }