@caweb/html-webpack-plugin 1.8.3 → 1.8.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 +10 -0
  2. package/index.js +40 -17
  3. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ v1.8.6
2
+ - Updated npm packages
3
+
4
+ v1.8.5
5
+ - Updated npm packages
6
+
7
+ v1.8.4
8
+ - Meta is now passed to templateParameters and removed from top level, the html-webpack-plugin meta tags are missing the self closing forward slash
9
+ - Media that's applied via style attributes using the url function are now emitted to the output directory as well
10
+
1
11
  v1.8.3
2
12
  - Updated npm packages
3
13
 
package/index.js CHANGED
@@ -43,16 +43,16 @@ class CAWebHtmlWebpackPlugin extends HtmlWebpackPlugin{
43
43
  inject: 'body',
44
44
  template: path.join( templatePath, 'patterns', 'index.html'),
45
45
  scriptLoading: 'blocking',
46
- meta: {
47
- "Author": "CAWebPublishing",
48
- "Description": "State of California",
49
- "Keywords": "California,government",
50
- "viewport": "width=device-width, initial-scale=1.0, maximum-scale=2.0"
51
- },
52
46
  templateParameters: {
53
47
  "template": "index",
54
48
  "title": path.basename( appPath ),
55
49
  "scheme": "oceanside",
50
+ "meta": {
51
+ "Author": "CAWebPublishing",
52
+ "Description": "State of California",
53
+ "Keywords": "California,government",
54
+ "viewport": "width=device-width, initial-scale=1.0, maximum-scale=2.0"
55
+ }
56
56
  },
57
57
  assets: []
58
58
  }
@@ -103,6 +103,17 @@ class CAWebHtmlWebpackPlugin extends HtmlWebpackPlugin{
103
103
  defaultOptions.templateParameters.template = template;
104
104
  }
105
105
 
106
+ // if the user options has meta tags we merge them with the defaultOptions.templateParameters.meta
107
+ // and clear the meta key
108
+ if( opts.meta ){
109
+ defaultOptions.templateParameters.meta = {
110
+ ...defaultOptions.templateParameters.meta,
111
+ ...opts.meta
112
+ }
113
+
114
+ delete opts.meta;
115
+ }
116
+
106
117
  // if there is a caweb.json file we merge the site data with the templateParameters
107
118
  if( fs.existsSync( path.join(appPath, 'caweb.json') ) ){
108
119
 
@@ -145,17 +156,30 @@ class CAWebHtmlWebpackPlugin extends HtmlWebpackPlugin{
145
156
  ({html, outputName, plugin}, cb) => {
146
157
  // if the html contains local assets those assets are added to the options.assets array
147
158
  // and the assets are added to the compilation afterEmit
148
- let additionalAssets = html.match(/(src|href)="(.+?)"/g);
159
+ let srcHrefAssets = html.match(/(src|href)="(.+?)"/g);
160
+ let styleAssets = html.match(/style=".*url\((\S+)\)/g);
161
+
162
+ let allAssets = [];
149
163
 
150
- if( additionalAssets ){
151
- additionalAssets.forEach( (asset) => {
152
- let ref = asset.replace(/(src|href|=|")/g, '');
164
+ // if the html contains url() in the style attributes
165
+ if( styleAssets ){
166
+ styleAssets = styleAssets.map( s => s.replace(/(style=".*url\(|["'()])/g, '') )
167
+ // |["'\(\)]
168
+ allAssets = [...allAssets, ...styleAssets];
169
+ }
170
+
171
+ // if the html contains src or href attributes
172
+ if( srcHrefAssets ){
173
+ srcHrefAssets = srcHrefAssets.map( s => s.replace(/(src|href|=|")/g, '') );
174
+
175
+ allAssets = [...allAssets, ...srcHrefAssets];
176
+ }
177
+
178
+ allAssets.forEach( asset =>{
179
+ let localFile = asset.startsWith('/') || asset.startsWith('\\') ?
180
+ path.join( appPath, asset ) :
181
+ asset;
153
182
 
154
-
155
- let localFile = ref.startsWith('/') || ref.startsWith('\\') ?
156
- path.join( appPath, ref ) :
157
- ref;
158
-
159
183
  // if the asset is a local file
160
184
  // if the asset is not already in the options.assets array
161
185
  if(
@@ -165,13 +189,12 @@ class CAWebHtmlWebpackPlugin extends HtmlWebpackPlugin{
165
189
  ){
166
190
  this.options.assets.push(localFile);
167
191
  }
168
- });
192
+ });
169
193
 
170
194
  // any references to the node_modules directory are removed
171
195
  // any organizational packages @ are also removed
172
196
  // this might cause some conflicts with packages that are named the same as organiazational packages
173
197
  html = html.replace(/[\\\/]?node_modules[\\\/@]+/g, '/');
174
- }
175
198
 
176
199
  // Tell webpack to move on
177
200
  cb(null, {html, outputName, plugin});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/html-webpack-plugin",
3
- "version": "1.8.3",
3
+ "version": "1.8.6",
4
4
  "description": "CAWebPublishing Site Generation HTML Webpack Plugin",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "homepage": "https://github.com/CAWebPublishing/webpack/plugins/html#readme",
31
31
  "dependencies": {
32
- "@caweb/template": "^1.0.0-beta.2",
32
+ "@caweb/template": "^1.0.1",
33
33
  "html-webpack-plugin": "^5.6.3",
34
- "webpack": "^5.99.8",
34
+ "webpack": "^5.99.9",
35
35
  "webpack-cli": "^6.0.1"
36
36
  }
37
37
  }