@caweb/webpack 1.1.4 → 1.2.1
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/package.json +6 -13
- package/webpack.config.js +23 -202
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caweb/webpack",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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
|
|
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,12 @@
|
|
|
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.
|
|
48
|
-
"@caweb/css-audit-webpack-plugin": "^1.0.
|
|
49
|
-
"@caweb/html-webpack-plugin": "^1.1
|
|
50
|
-
"@caweb/jshint-webpack-plugin": "^1.0.
|
|
42
|
+
"@caweb/a11y-webpack-plugin": "^1.0.5",
|
|
43
|
+
"@caweb/css-audit-webpack-plugin": "^1.0.5",
|
|
44
|
+
"@caweb/html-webpack-plugin": "^1.2.1",
|
|
45
|
+
"@caweb/jshint-webpack-plugin": "^1.0.6",
|
|
51
46
|
"@wordpress/scripts": "^28.4.0",
|
|
52
|
-
"handlebars-loader": "^1.7.3",
|
|
53
|
-
"html-webpack-plugin": "^5.6.0",
|
|
54
47
|
"html-webpack-skip-assets-plugin": "^1.0.4"
|
|
55
48
|
}
|
|
56
49
|
}
|
package/webpack.config.js
CHANGED
|
@@ -1,227 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
|
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'];
|
|
18
|
+
import {HtmlWebpackSkipAssetsPlugin} from 'html-webpack-skip-assets-plugin';
|
|
122
19
|
|
|
123
|
-
|
|
20
|
+
let template = 'default';
|
|
21
|
+
let scheme = 'oceanside';
|
|
124
22
|
|
|
125
|
-
|
|
126
|
-
|
|
23
|
+
// Allow for template to be selected via NODE_OPTIONS env variable
|
|
24
|
+
if( process.env.NODE_OPTIONS ){
|
|
127
25
|
let opts = process.env.NODE_OPTIONS.split(' ').filter(e=>e).map(o=>o.replaceAll("'", ''))
|
|
128
26
|
if( opts.includes('--template') ){
|
|
129
|
-
|
|
27
|
+
template = opts[opts.indexOf('--template') + 1]
|
|
130
28
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// Dev Server is added
|
|
136
|
-
webpackConfig.devServer = {
|
|
137
|
-
...baseConfig.devServer,
|
|
138
|
-
hot: true,
|
|
139
|
-
compress: true,
|
|
140
|
-
open: [ 'http://localhost:9000' ],
|
|
141
|
-
port: 9000,
|
|
142
|
-
static: [
|
|
143
|
-
/**
|
|
144
|
-
* Static files are served from the following files in the following order
|
|
145
|
-
* we don't have to add the build directory since that is the output.path and proxied
|
|
146
|
-
* public - Default
|
|
147
|
-
* node_modules - Allows loading files from other npm packages
|
|
148
|
-
* src - Allows loading files that aren't compiled
|
|
149
|
-
*/
|
|
150
|
-
{
|
|
151
|
-
directory: path.join(appPath, 'public'),
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
directory: path.join(appPath, 'node_modules'),
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
directory: path.join(appPath, 'src'),
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
proxy:[
|
|
161
|
-
/**
|
|
162
|
-
* WordPress Proxy Configuration is deprecated
|
|
163
|
-
* @since 28.2.0
|
|
164
|
-
*/
|
|
165
|
-
{
|
|
166
|
-
context: ['/build'],
|
|
167
|
-
target: 'http://localhost:9000',
|
|
168
|
-
pathRewrite: {
|
|
169
|
-
'^/build': ''
|
|
170
|
-
},
|
|
171
|
-
logLevel: 'info'
|
|
172
|
-
},
|
|
173
|
-
/**
|
|
174
|
-
* We proxy the node_modules and src so they serve from the root
|
|
175
|
-
*/
|
|
176
|
-
{
|
|
177
|
-
context: ['/node_modules'],
|
|
178
|
-
target: 'http://localhost:9000',
|
|
179
|
-
pathRewrite: { '^/node_modules': '' },
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
context: ['/src'],
|
|
183
|
-
target: 'http://localhost:9000',
|
|
184
|
-
pathRewrite: { '^/src': '' },
|
|
185
|
-
}
|
|
186
|
-
]
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
let pageTemplate = {
|
|
190
|
-
title : path.basename(appPath),
|
|
191
|
-
filename: path.join( appPath, 'public', 'index.html'),
|
|
192
|
-
template: path.join( appPath, 'node_modules', '@caweb', 'html-webpack-plugin', 'sample', `${template}.html`),
|
|
193
|
-
favicon: fs.existsSync(path.join(samplePath, 'favicon.ico')) ? path.join(samplePath, 'favicon.ico') : false,
|
|
194
|
-
minify: false,
|
|
195
|
-
scriptLoading: 'blocking',
|
|
196
|
-
inject: 'body',
|
|
197
|
-
meta: {
|
|
198
|
-
"Author": "CAWebPublishing",
|
|
199
|
-
"Description": "State of California",
|
|
200
|
-
"Keywords": "California,government",
|
|
201
|
-
"viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
|
|
202
|
-
},
|
|
203
|
-
templateParameters: {
|
|
204
|
-
"title" : path.basename(appPath),
|
|
205
|
-
"header": '/sample/structural/header.html',
|
|
206
|
-
"content": '/sample/index.html',
|
|
207
|
-
"footer": '/sample/structural/footer.html'
|
|
208
|
-
},
|
|
209
|
-
skipAssets: [
|
|
210
|
-
/.*-rtl.css/, // we skip the Right-to-Left Styles
|
|
211
|
-
/css-audit.*/, // we skip the CSSAudit Files
|
|
212
|
-
/a11y.*/, // we skip the A11y Files
|
|
213
|
-
/jshint.*/, // we skip the JSHint Files
|
|
214
|
-
]
|
|
215
|
-
}
|
|
29
|
+
if( opts.includes('--scheme') ){
|
|
30
|
+
scheme = opts[opts.indexOf('--scheme') + 1]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
216
33
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
new
|
|
34
|
+
// Page Template and additional plugins
|
|
35
|
+
webpackConfig.plugins.push(
|
|
36
|
+
new CAWebHTMLPlugin({
|
|
37
|
+
template,
|
|
38
|
+
templateParameters: {
|
|
39
|
+
scheme
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
220
42
|
new HtmlWebpackSkipAssetsPlugin(),
|
|
221
43
|
new JSHintPlugin(),
|
|
222
44
|
new CSSAuditPlugin(),
|
|
223
45
|
new A11yPlugin()
|
|
224
|
-
|
|
225
|
-
}
|
|
46
|
+
)
|
|
226
47
|
|
|
227
48
|
export default webpackConfig;
|