@caweb/webpack 1.1.3 → 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 (2) hide show
  1. package/package.json +7 -15
  2. package/webpack.config.js +9 -211
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/webpack",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "description": "CAWebPublishing Webpack Configuration",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "webpack": "webpack",
12
12
  "preserve": "cd plugins/html && npm i",
13
- "serve": "set NODE_OPTIONS='--no-selectors' && webpack serve --config ./webpack.config.js ./plugins/html/entry/oceanside.js --merge",
13
+ "serve": "set NODE_OPTIONS='--no-selectors' && webpack serve --config ./webpack.config.js",
14
14
  "build": "npm run build:html",
15
15
  "build:html": "cd ./plugins/html/ && npm run build",
16
16
  "u:deps": "node ./scripts/update-deps.js ./plugins",
@@ -38,19 +38,11 @@
38
38
  "access": "public"
39
39
  },
40
40
  "homepage": "https://github.com/CAWebPublishing/webpack#readme",
41
- "devDependencies": {
42
- "rimraf": "^6.0.1",
43
- "webpack": "^5.93.0",
44
- "webpack-cli": "^5.1.4"
45
- },
46
41
  "dependencies": {
47
- "@caweb/a11y-webpack-plugin": "^1.0.4",
48
- "@caweb/css-audit-webpack-plugin": "^1.0.4",
49
- "@caweb/html-webpack-plugin": "^1.1.1",
50
- "@caweb/jshint-webpack-plugin": "^1.0.5",
51
- "@wordpress/scripts": "^28.4.0",
52
- "handlebars-loader": "^1.7.3",
53
- "html-webpack-plugin": "^5.6.0",
54
- "html-webpack-skip-assets-plugin": "^1.0.4"
42
+ "@caweb/a11y-webpack-plugin": "^1.0.5",
43
+ "@caweb/css-audit-webpack-plugin": "^1.0.5",
44
+ "@caweb/html-webpack-plugin": "^1.2.0",
45
+ "@caweb/jshint-webpack-plugin": "^1.0.6",
46
+ "@wordpress/scripts": "^28.4.0"
55
47
  }
56
48
  }
package/webpack.config.js CHANGED
@@ -1,232 +1,30 @@
1
1
  /**
2
- * WebPack Configuration for California Department of Technology
3
- *
4
- * Utilizes WordPress Scripts Webpack configuration as base.
2
+ * Webpack Configuration
5
3
  *
4
+ * @see @caweb/html-webpack-plugin/webpack.config.js
6
5
  * @link https://webpack.js.org/configuration/
7
6
  */
8
7
 
9
8
  /**
10
9
  * External dependencies
11
10
  */
12
- import baseConfig from '@wordpress/scripts/config/webpack.config.js';
13
- import path from 'path';
14
- import fs from 'fs';
15
- import HtmlWebpackPlugin from 'html-webpack-plugin';
16
- import {HtmlWebpackSkipAssetsPlugin} from 'html-webpack-skip-assets-plugin';
11
+ import webpackConfig from '@caweb/html-webpack-plugin/webpack.config.js';
17
12
 
13
+ import CAWebHTMLPlugin from '@caweb/html-webpack-plugin';
18
14
  import JSHintPlugin from '@caweb/jshint-webpack-plugin';
19
15
  import CSSAuditPlugin from '@caweb/css-audit-webpack-plugin';
20
16
  import A11yPlugin from '@caweb/a11y-webpack-plugin';
21
17
 
22
- /**
23
- * Internal dependencies
24
- */
25
- const webpackCommand = 'build' === process.argv[2] ? 'build' : 'serve' ;
26
-
27
- // Update some of the default WordPress webpack rules.
28
- baseConfig.module.rules.forEach((rule, i) => {
29
- const r = new RegExp(rule.test).toString();
30
-
31
- switch(r){
32
- // WordPress adds a hash to asset file names we remove that hash.
33
- case new RegExp(/\.(bmp|png|jpe?g|gif|webp)$/i).toString():
34
- rule.generator.filename = 'images/[name][ext]';
35
- break;
36
- case new RegExp(/\.(woff|woff2|eot|ttf|otf)$/i).toString():
37
- rule.generator.filename = 'fonts/[name][ext]';
38
- break;
39
- case new RegExp(/\.svg$/).toString():
40
- // we don't want SVG to be asset/inline otherwise the resource may not be available.
41
- // the asset should be an asset/resource we move them to the fonts folder.
42
- if( 'asset/inline' === rule.type ){
43
- rule.type = 'asset/resource';
44
- rule.generator = { filename: 'fonts/[name][ext]' };
45
-
46
- delete rule.issuer;
47
- }
48
- break;
49
- }
50
- });
51
-
52
- let webpackConfig = {
53
- ...baseConfig,
54
- target: 'web',
55
- cache: false,
56
- stats: 'errors',
57
- output: {
58
- ...baseConfig.output,
59
- clean: true,
60
- //publicPath: `/public`
61
- },
62
- module: {
63
- ...baseConfig.module,
64
- rules: [
65
- ...baseConfig.module.rules,
66
- /**
67
- * Default template loader for html is lodash,
68
- * lets switch to handlebars
69
- */
70
- {
71
- test: /\.html$/,
72
- loader: 'handlebars-loader',
73
- options:{
74
- rootRelative: process.cwd(),
75
- partialResolver: function(partial, callback){
76
- // all template partials are loaded from the root sample directory
77
- let partialPath = path.join( process.cwd(), 'sample' );
78
- let partialStructurePath = path.join( partialPath, 'structural' );
79
-
80
- // template parameter specific partials
81
- switch( partial ){
82
- // header/footer is served from the /sample/structural/ directory
83
- case 'footer':
84
- case 'header':
85
- partialPath = fs.existsSync(path.join( partialStructurePath, `/${partial}.html` )) ? path.join( partialStructurePath, `/${partial}.html` ) :
86
- `./structural/${partial}.html`
87
-
88
- break;
89
-
90
- // content is served from the /sample/index.html
91
- case 'content':
92
- partialPath = fs.existsSync(path.join( partialPath, '/index.html' )) ? path.join( partialPath, '/index.html' ) :
93
- './missing/content.html';
94
-
95
- break;
96
-
97
- // if not a template parameter we let the loader handle it
98
- default:
99
- partialPath = partial;
100
- }
101
-
102
-
103
- callback(false, partialPath );
104
- }
105
- }
106
- }
107
- ]
108
- },
109
- performance: {
110
- maxAssetSize: 500000,
111
- maxEntrypointSize: 500000
112
- },
113
- };
114
-
115
- /**
116
- * Serve Only
117
- */
118
- if( 'serve' === webpackCommand ){
119
- const appPath = process.cwd();
120
- const samplePath = path.join( appPath, 'sample');
121
- const templates = ['blank', 'default'];
122
-
123
- let template;
124
-
125
- // Allow for template to be selected via NODE_OPTIOS env variable
126
- if( process.env.NODE_OPTIONS ){
127
- let opts = process.env.NODE_OPTIONS.split(' ').filter(e=>e).map(o=>o.replaceAll("'", ''))
128
- if( opts.includes('--template') ){
129
- template = opts[opts.indexOf('--template') + 1]
130
- }
131
- }
132
-
133
- // Arguments passed to the process supersede env vars
134
- if( process.argv.includes('--template') ){
135
- template = process.argv[process.argv.indexOf('--template') + 1];
136
- }
137
-
138
- template = templates.includes(template) ? template : 'default';
139
-
140
- // Dev Server is added
141
- webpackConfig.devServer = {
142
- ...baseConfig.devServer,
143
- hot: true,
144
- compress: true,
145
- open: [ 'http://localhost:9000' ],
146
- port: 9000,
147
- static: [
148
- /**
149
- * Static files are served from the following files in the following order
150
- * we don't have to add the build directory since that is the output.path and proxied
151
- * public - Default
152
- * node_modules - Allows loading files from other npm packages
153
- * src - Allows loading files that aren't compiled
154
- */
155
- {
156
- directory: path.join(appPath, 'public'),
157
- },
158
- {
159
- directory: path.join(appPath, 'node_modules'),
160
- },
161
- {
162
- directory: path.join(appPath, 'src'),
163
- },
164
- ],
165
- proxy:[
166
- /**
167
- * WordPress Proxy Configuration is deprecated
168
- * @since 28.2.0
169
- */
170
- {
171
- context: ['/build'],
172
- target: 'http://localhost:9000',
173
- pathRewrite: {
174
- '^/build': ''
175
- },
176
- logLevel: 'info'
177
- },
178
- /**
179
- * We proxy the node_modules and src so they serve from the root
180
- */
181
- {
182
- context: ['/node_modules'],
183
- target: 'http://localhost:9000',
184
- pathRewrite: { '^/node_modules': '' },
185
- },
186
- {
187
- context: ['/src'],
188
- target: 'http://localhost:9000',
189
- pathRewrite: { '^/src': '' },
190
- }
191
- ]
192
- }
18
+ import {HtmlWebpackSkipAssetsPlugin} from 'html-webpack-skip-assets-plugin';
193
19
 
194
- let pageTemplate = {
195
- title : path.basename(appPath),
196
- filename: path.join( appPath, 'public', 'index.html'),
197
- template: path.join( appPath, 'node_modules', '@caweb', 'html-webpack-plugin', 'sample', `${template}.html`),
198
- favicon: fs.existsSync(path.join(samplePath, 'favicon.ico')) ? path.join(samplePath, 'favicon.ico') : false,
199
- minify: false,
200
- scriptLoading: 'blocking',
201
- inject: 'body',
202
- meta: {
203
- "Author": "CAWebPublishing",
204
- "Description": "State of California",
205
- "Keywords": "California,government",
206
- "viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
207
- },
208
- templateParameters: {
209
- "title" : path.basename(appPath),
210
- "header": '/sample/structural/header.html',
211
- "content": '/sample/index.html',
212
- "footer": '/sample/structural/footer.html'
213
- },
214
- skipAssets: [
215
- /.*-rtl.css/, // we skip the Right-to-Left Styles
216
- /css-audit.*/, // we skip the CSSAudit Files
217
- /a11y.*/, // we skip the A11y Files
218
- /jshint.*/, // we skip the JSHint Files
219
- ]
220
- }
221
20
 
222
- // Page Template and additional plugins
223
- webpackConfig.plugins.push(
224
- new HtmlWebpackPlugin(pageTemplate),
21
+ // Page Template and additional plugins
22
+ webpackConfig.plugins.push(
23
+ new CAWebHTMLPlugin(),
225
24
  new HtmlWebpackSkipAssetsPlugin(),
226
25
  new JSHintPlugin(),
227
26
  new CSSAuditPlugin(),
228
27
  new A11yPlugin()
229
- )
230
- }
28
+ )
231
29
 
232
30
  export default webpackConfig;