@caweb/webpack 1.0.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.
- package/README.md +0 -0
- package/package.json +60 -0
- package/webpack.config.js +184 -0
package/README.md
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@caweb/webpack",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CAWebPublishing Webpack Configuration",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"webpack.config.js"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"webpack": "webpack",
|
|
12
|
+
"serve": "webpack serve --entry-reset --entry ./plugins/html/src/index.js",
|
|
13
|
+
"update": "npm run build:plugins && npm run install:plugins",
|
|
14
|
+
"build": "npm run build:plugins",
|
|
15
|
+
"build:plugins": "npm run build:html",
|
|
16
|
+
"build:html": "webpack build --entry-reset --entry ./plugins/html/src/index.js --output-path ./plugins/html/build/ && renamer --find main --replace index ./plugins/html/build/*.* -s",
|
|
17
|
+
"preinstall:plugins": "npm run pack:plugins",
|
|
18
|
+
"install:plugins": "npm i ./plugins/html/package.tgz",
|
|
19
|
+
"postinstall:plugins": "rimraf --glob ./plugins/**/package.tgz",
|
|
20
|
+
"pack:plugins": "npm run pack:html",
|
|
21
|
+
"pack:html": "npm pack ./plugins/html/ --pack-destination ./plugins/html/",
|
|
22
|
+
"postpack:plugins": "renamer --find /.*.tgz/ --replace package.tgz ./plugins/**/*.tgz -s",
|
|
23
|
+
"test": "echo \\\"Error: run tests from root\\\" && exit 0",
|
|
24
|
+
"i:local": "npm i plugins/a11y/ plugins/css-audit/ plugins/html/ plugins/jshint/ --save-dev",
|
|
25
|
+
"un:local": "npm un plugins/a11y/ plugins/css-audit/ plugins/html/ plugins/jshint/ --force"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/CAWebPublishing/webpack.git"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"caweb",
|
|
33
|
+
"cagov",
|
|
34
|
+
"webpack"
|
|
35
|
+
],
|
|
36
|
+
"author": "CAWebPublishing",
|
|
37
|
+
"license": "ISC",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/CAWebPublishing/webpack/issues"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/CAWebPublishing/webpack#readme",
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"renamer": "^5.0.1",
|
|
47
|
+
"rimraf": "^6.0.1",
|
|
48
|
+
"webpack": "^5.93.0",
|
|
49
|
+
"webpack-cli": "^5.1.4"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@caweb/a11y-webpack-plugin": "^1.0.0",
|
|
53
|
+
"@caweb/css-audit-webpack-plugin": "^1.0.0",
|
|
54
|
+
"@caweb/html-webpack-plugin": "^1.0.1",
|
|
55
|
+
"@caweb/jshint-webpack-plugin": "^1.0.0",
|
|
56
|
+
"@wordpress/scripts": "^28.3.0",
|
|
57
|
+
"html-webpack-plugin": "^5.6.0",
|
|
58
|
+
"html-webpack-skip-assets-plugin": "^1.0.4"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
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 path from 'path';
|
|
14
|
+
import fs from 'fs';
|
|
15
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
16
|
+
import {HtmlWebpackSkipAssetsPlugin} from 'html-webpack-skip-assets-plugin';
|
|
17
|
+
|
|
18
|
+
import JSHintPlugin from '@caweb/jshint-webpack-plugin';
|
|
19
|
+
import CSSAuditPlugin from '@caweb/css-audit-webpack-plugin';
|
|
20
|
+
import A11yPlugin from '@caweb/a11y-webpack-plugin';
|
|
21
|
+
|
|
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-warnings',
|
|
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
|
+
}
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
performance: {
|
|
77
|
+
maxAssetSize: 500000,
|
|
78
|
+
maxEntrypointSize: 500000
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Serve Only
|
|
84
|
+
*/
|
|
85
|
+
if( 'serve' === webpackCommand ){
|
|
86
|
+
const appPath = process.cwd();
|
|
87
|
+
|
|
88
|
+
// if the project has a sample index page we load it,
|
|
89
|
+
// otherwise fallback to @caweb/html-webpack-plugin/sample
|
|
90
|
+
const samplePath = fs.existsSync(path.join(appPath, 'sample')) ?
|
|
91
|
+
path.join( appPath, 'sample') : path.join( appPath, 'node_modules', '@caweb', 'html-webpack-plugin', 'sample');
|
|
92
|
+
//const srcPath = path.join( appPath, 'src');
|
|
93
|
+
//const dataPath = path.join( srcPath, 'data');
|
|
94
|
+
|
|
95
|
+
// Dev Server is added
|
|
96
|
+
webpackConfig.devServer = {
|
|
97
|
+
...baseConfig.devServer,
|
|
98
|
+
hot: true,
|
|
99
|
+
compress: true,
|
|
100
|
+
open: [ 'http://localhost:9000' ],
|
|
101
|
+
port: 9000,
|
|
102
|
+
static: [
|
|
103
|
+
/**
|
|
104
|
+
* Static files are served from the following files in the following order
|
|
105
|
+
* we don't have to add the build directory since that is the output.path and proxied
|
|
106
|
+
* public - Default
|
|
107
|
+
* node_modules - Allows loading files from other npm packages
|
|
108
|
+
* src - Allows loading files that aren't compiled
|
|
109
|
+
*/
|
|
110
|
+
{
|
|
111
|
+
directory: path.join(appPath, 'public'),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
directory: path.join(appPath, 'node_modules'),
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
directory: path.join(appPath, 'src'),
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
proxy:[
|
|
121
|
+
/**
|
|
122
|
+
* WordPress Proxy Configuration is deprecated
|
|
123
|
+
* @since 28.2.0
|
|
124
|
+
*/
|
|
125
|
+
{
|
|
126
|
+
context: ['/build'],
|
|
127
|
+
target: 'http://localhost:9000',
|
|
128
|
+
pathRewrite: {
|
|
129
|
+
'^/build': ''
|
|
130
|
+
},
|
|
131
|
+
logLevel: 'info'
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* We proxy the node_modules and src so they serve from the root
|
|
135
|
+
*/
|
|
136
|
+
{
|
|
137
|
+
context: ['/node_modules'],
|
|
138
|
+
target: 'http://localhost:9000',
|
|
139
|
+
pathRewrite: { '^/node_modules': '' },
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
context: ['/src'],
|
|
143
|
+
target: 'http://localhost:9000',
|
|
144
|
+
pathRewrite: { '^/src': '' },
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let pageTemplate = {
|
|
150
|
+
title : path.basename(appPath),
|
|
151
|
+
filename: path.join( appPath, 'public', 'index.html'),
|
|
152
|
+
template: path.join(samplePath, 'index.html'),
|
|
153
|
+
favicon: fs.existsSync(path.join(samplePath, 'favicon.ico')) ? path.join(samplePath, 'favicon.ico') : false,
|
|
154
|
+
minify: false,
|
|
155
|
+
scriptLoading: 'blocking',
|
|
156
|
+
inject: 'body',
|
|
157
|
+
meta: {
|
|
158
|
+
"Author": "CAWebPublishing",
|
|
159
|
+
"Description": "State of California",
|
|
160
|
+
"Keywords": "California,government",
|
|
161
|
+
"viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
|
|
162
|
+
},
|
|
163
|
+
templateParameters: {
|
|
164
|
+
"title" : path.basename(appPath)
|
|
165
|
+
},
|
|
166
|
+
skipAssets: [
|
|
167
|
+
'**/*-rtl.css', // we skip the Right-to-Left Styles
|
|
168
|
+
'**/css-audit.*', // we skip the CSSAudit Files
|
|
169
|
+
'**/a11y.*', // we skip the A11y Files
|
|
170
|
+
'**/jshint.*', // we skip the JSHint Files
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Page Template and additional plugins
|
|
175
|
+
webpackConfig.plugins.push(
|
|
176
|
+
new HtmlWebpackPlugin(pageTemplate),
|
|
177
|
+
new HtmlWebpackSkipAssetsPlugin(),
|
|
178
|
+
new JSHintPlugin(),
|
|
179
|
+
new CSSAuditPlugin(),
|
|
180
|
+
new A11yPlugin()
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export default webpackConfig;
|