@caweb/html-webpack-plugin 1.1.1 → 1.2.0

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 (53) hide show
  1. package/build/delta-rtl.css +6 -6
  2. package/build/delta.asset.php +1 -1
  3. package/build/delta.css +6 -6
  4. package/build/delta.js.map +1 -1
  5. package/build/eureka-rtl.css +6 -6
  6. package/build/eureka.asset.php +1 -1
  7. package/build/eureka.css +6 -6
  8. package/build/eureka.js.map +1 -1
  9. package/build/mono-rtl.css +6 -6
  10. package/build/mono.asset.php +1 -1
  11. package/build/mono.css +6 -6
  12. package/build/mono.js.map +1 -1
  13. package/build/oceanside-rtl.css +6 -6
  14. package/build/oceanside.asset.php +1 -1
  15. package/build/oceanside.css +6 -6
  16. package/build/oceanside.js.map +1 -1
  17. package/build/orangecounty-rtl.css +6 -6
  18. package/build/orangecounty.asset.php +1 -1
  19. package/build/orangecounty.css +6 -6
  20. package/build/orangecounty.js.map +1 -1
  21. package/build/pasorobles-rtl.css +6 -6
  22. package/build/pasorobles.asset.php +1 -1
  23. package/build/pasorobles.css +6 -6
  24. package/build/pasorobles.js.map +1 -1
  25. package/build/sacramento-rtl.css +6 -6
  26. package/build/sacramento.asset.php +1 -1
  27. package/build/sacramento.css +6 -6
  28. package/build/sacramento.js.map +1 -1
  29. package/build/santabarbara-rtl.css +6 -6
  30. package/build/santabarbara.asset.php +1 -1
  31. package/build/santabarbara.css +6 -6
  32. package/build/santabarbara.js.map +1 -1
  33. package/build/santacruz-rtl.css +6 -6
  34. package/build/santacruz.asset.php +1 -1
  35. package/build/santacruz.css +6 -6
  36. package/build/santacruz.js.map +1 -1
  37. package/build/shasta-rtl.css +6 -6
  38. package/build/shasta.asset.php +1 -1
  39. package/build/shasta.css +6 -6
  40. package/build/shasta.js.map +1 -1
  41. package/build/sierra-rtl.css +6 -6
  42. package/build/sierra.asset.php +1 -1
  43. package/build/sierra.css +6 -6
  44. package/build/sierra.js.map +1 -1
  45. package/build/trinity-rtl.css +6 -6
  46. package/build/trinity.asset.php +1 -1
  47. package/build/trinity.css +6 -6
  48. package/build/trinity.js.map +1 -1
  49. package/index.js +82 -0
  50. package/package.json +15 -4
  51. package/sample/default.html +7 -0
  52. package/webpack.config.js +172 -0
  53. /package/sample/{index.html → blank.html} +0 -0
package/index.js ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import path from 'path';
7
+ import chalk from 'chalk';
8
+ import deepmerge from 'deepmerge';
9
+ import { fileURLToPath, URL } from 'url';
10
+ import HtmlWebpackPlugin from 'html-webpack-plugin';
11
+ /*
12
+ import spawn from 'cross-spawn';
13
+ import { getAllFilesSync } from 'get-all-files'
14
+ import EntryDependency from "webpack/lib/dependencies/EntryDependency.js";
15
+ import fs from 'fs';
16
+
17
+ const boldWhite = chalk.bold.white;
18
+ const boldGreen = chalk.bold.green;
19
+ const boldBlue = chalk.bold.hex('#03a7fc');
20
+ */
21
+ const currentPath = path.dirname(fileURLToPath(import.meta.url));
22
+ const appPath = process.cwd();
23
+
24
+
25
+ /**
26
+ * Launches CAWeb HTML Markup
27
+ *
28
+ * Requires the devServer to be able to writeToDisk
29
+ * devMiddleware: {
30
+ * writeToDisk: true,
31
+ * }
32
+ *
33
+ * @class CAWebHTMLPlugin
34
+ * @typedef {CAWebHTMLPlugin}
35
+ * @extends {HtmlWebpackPlugin}
36
+ */
37
+ class CAWebHTMLPlugin extends HtmlWebpackPlugin{
38
+
39
+ // we change some of the html-webpack-plugin defaults
40
+ constructor(opts = {}) {
41
+ let templates = ['blank', 'default'];
42
+
43
+ let defaultOptions = {
44
+ title: path.basename( appPath ),
45
+ inject: 'body',
46
+ template: path.join( currentPath, 'sample', 'default.html'),
47
+ scriptLoading: 'blocking',
48
+ meta: {
49
+ "Author": "CAWebPublishing",
50
+ "Description": "State of California",
51
+ "Keywords": "California,government",
52
+ "viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
53
+ },
54
+ templateParameters: {
55
+ "title": path.basename( appPath ),
56
+ "scheme": "oceanside"
57
+ },
58
+ }
59
+
60
+ // update templateParameters.title to match user options.
61
+ if( opts.title ){
62
+ defaultOptions.templateParameters.title = opts.title;
63
+ }
64
+
65
+ // select template file based on template selection if template is one of ours
66
+ if( opts.template && templates.includes(opts.template) ){
67
+ opts.template = path.join( currentPath, 'sample', `${opts.template}.html`);
68
+ }
69
+
70
+ // console.log(deepmerge(defaultOptions, opts))
71
+ super(deepmerge(defaultOptions, opts));
72
+
73
+ }
74
+
75
+ apply(compiler) {
76
+ super.apply(compiler);
77
+ console.log( compiler.options );
78
+ }
79
+ } // end of class
80
+
81
+
82
+ export default CAWebHTMLPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/html-webpack-plugin",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "CAWebPublishing Sample Page and Configurations",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -8,12 +8,15 @@
8
8
  "build",
9
9
  "entry",
10
10
  "sample",
11
- "README.md"
11
+ "index.js",
12
+ "README.md",
13
+ "webpack.config.js"
12
14
  ],
13
15
  "scripts": {
14
16
  "webpack": "webpack",
15
- "build": "webpack build --config ../../webpack.config.js ./webpack.config.js --merge",
17
+ "build": "webpack build --config ./webpack.config.js ./scripts/create-entrypoints.js --merge",
16
18
  "postbuild": "node ./scripts/create-entrypoints.js",
19
+ "serve": "webpack serve --config ./webpack.config.js ./entry/oceanside.js ./scripts/webpack.test.js --merge",
17
20
  "test": "echo \"Error: run tests from root\" && exit 0"
18
21
  },
19
22
  "repository": {
@@ -36,6 +39,14 @@
36
39
  },
37
40
  "homepage": "https://github.com/CAWebPublishing/webpack/plugins/html#readme",
38
41
  "devDependencies": {
39
- "bootstrap": "^5.3.3"
42
+ "bootstrap": "^5.3.3",
43
+ "html-webpack-skip-assets-plugin": "^1.0.4",
44
+ "webpack": "^5.93.0",
45
+ "webpack-cli": "^5.1.4"
46
+ },
47
+ "dependencies": {
48
+ "@wordpress/scripts": "^28.4.0",
49
+ "handlebars-loader": "^1.7.3",
50
+ "html-webpack-plugin": "^5.6.0"
40
51
  }
41
52
  }
@@ -1,6 +1,9 @@
1
1
  <html lang="en">
2
2
  <head>
3
3
  <title>{{ title }}</title>
4
+ {{#if scheme }}
5
+ <link rel="stylesheet" href="node_modules/@caweb/html-webpack-plugin/build/{{ scheme }}.css" />
6
+ {{/if}}
4
7
  </head>
5
8
  <body>
6
9
  {{> header }}
@@ -12,5 +15,9 @@
12
15
  </div>
13
16
  </div>
14
17
  {{> footer }}
18
+
19
+ {{#if scheme }}
20
+ <script src="node_modules/@caweb/html-webpack-plugin/build/{{ scheme }}.js"></script>
21
+ {{/if}}
15
22
  </body>
16
23
  </html>
@@ -0,0 +1,172 @@
1
+ /**
2
+ * WebPack Configuration for California Department of Technology
3
+ *
4
+ * Utilizes WordPress Scripts Webpack configuration as base.
5
+ *
6
+ * @link https://webpack.js.org/configuration/
7
+ */
8
+
9
+ /**
10
+ * External Dependencies
11
+ */
12
+ import baseConfig from '@wordpress/scripts/config/webpack.config.js';
13
+ import fs from 'fs';
14
+ import path from 'path';
15
+ import { fileURLToPath } from 'url';
16
+
17
+ /**
18
+ * Internal dependencies
19
+ */
20
+
21
+ const webpackCommand = 'build' === process.argv[2] ? 'build' : 'serve' ;
22
+
23
+ // Update some of the default WordPress webpack rules.
24
+ baseConfig.module.rules.forEach((rule, i) => {
25
+ const r = new RegExp(rule.test).toString();
26
+
27
+ switch(r){
28
+ // WordPress adds a hash to asset file names we remove that hash.
29
+ case new RegExp(/\.(bmp|png|jpe?g|gif|webp)$/i).toString():
30
+ rule.generator.filename = 'images/[name][ext]';
31
+ break;
32
+ case new RegExp(/\.(woff|woff2|eot|ttf|otf)$/i).toString():
33
+ rule.generator.filename = 'fonts/[name][ext]';
34
+ break;
35
+ case new RegExp(/\.svg$/).toString():
36
+ // we don't want SVG to be asset/inline otherwise the resource may not be available.
37
+ // the asset should be an asset/resource we move them to the fonts folder.
38
+ if( 'asset/inline' === rule.type ){
39
+ rule.type = 'asset/resource';
40
+ rule.generator = { filename: 'fonts/[name][ext]' };
41
+
42
+ delete rule.issuer;
43
+ }
44
+ break;
45
+ }
46
+ });
47
+
48
+ let webpackConfig = {
49
+ ...baseConfig,
50
+ output: {
51
+ ...baseConfig.output,
52
+ clean: true,
53
+ },
54
+ target: 'web',
55
+ cache: false,
56
+ stats: 'errors',
57
+ performance: {
58
+ maxAssetSize: 500000,
59
+ maxEntrypointSize: 500000
60
+ },
61
+ module:{
62
+ ...baseConfig.module,
63
+ rules: [
64
+ ...baseConfig.module.rules,
65
+ /**
66
+ * Default template loader for html is lodash,
67
+ * lets switch to handlebars
68
+ */
69
+ {
70
+ test: /\.html$/,
71
+ loader: 'handlebars-loader',
72
+ options:{
73
+ rootRelative: process.cwd(),
74
+ partialResolver: function(partial, callback){
75
+ // all template partials are loaded from the root sample directory
76
+ let partialPath = path.join( process.cwd(), 'sample' );
77
+ let partialStructurePath = path.join( partialPath, 'structural' );
78
+
79
+ // template parameter specific partials
80
+ switch( partial ){
81
+ // header/footer is served from the /sample/structural/ directory
82
+ case 'footer':
83
+ case 'header':
84
+ partialPath = fs.existsSync(path.join( partialStructurePath, `/${partial}.html` )) ? path.join( partialStructurePath, `/${partial}.html` ) :
85
+ `./structural/${partial}.html`
86
+
87
+ break;
88
+
89
+ // content is served from the /sample/index.html
90
+ case 'content':
91
+ partialPath = fs.existsSync(path.join( partialPath, '/index.html' )) ? path.join( partialPath, '/index.html' ) :
92
+ './missing/content.html';
93
+
94
+ break;
95
+
96
+ // if not a template parameter we let the loader handle it
97
+ default:
98
+ partialPath = partial;
99
+ }
100
+
101
+
102
+ callback(false, partialPath );
103
+ }
104
+ }
105
+ }
106
+ ]
107
+ }
108
+ };
109
+
110
+ /**
111
+ * Serve Only
112
+ */
113
+ if( 'serve' === webpackCommand ){
114
+ const appPath = process.cwd();
115
+
116
+ // Dev Server is added
117
+ webpackConfig.devServer = {
118
+ ...baseConfig.devServer,
119
+ hot: true,
120
+ compress: true,
121
+ open: [ 'http://localhost:9000' ],
122
+ port: 9000,
123
+ static: [
124
+ /**
125
+ * Static files are served from the following files in the following order
126
+ * we don't have to add the build directory since that is the output.path and proxied
127
+ * public - Default
128
+ * node_modules - Allows loading files from other npm packages
129
+ * src - Allows loading files that aren't compiled
130
+ */
131
+ {
132
+ directory: path.join(appPath, 'public'),
133
+ },
134
+ {
135
+ directory: path.join(appPath, 'node_modules'),
136
+ },
137
+ {
138
+ directory: path.join(appPath, 'src'),
139
+ },
140
+ ],
141
+ proxy:[
142
+ /**
143
+ * WordPress Proxy Configuration is deprecated
144
+ * @since 28.2.0
145
+ */
146
+ {
147
+ context: ['/build'],
148
+ target: 'http://localhost:9000',
149
+ pathRewrite: {
150
+ '^/build': ''
151
+ },
152
+ logLevel: 'info'
153
+ },
154
+ /**
155
+ * We proxy the node_modules and src so they serve from the root
156
+ */
157
+ {
158
+ context: ['/node_modules'],
159
+ target: 'http://localhost:9000',
160
+ pathRewrite: { '^/node_modules': '' },
161
+ },
162
+ {
163
+ context: ['/src'],
164
+ target: 'http://localhost:9000',
165
+ pathRewrite: { '^/src': '' },
166
+ }
167
+ ]
168
+ }
169
+
170
+ }
171
+
172
+ export default webpackConfig;
File without changes