@caweb/webpack 1.4.4 → 1.5.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/package.json +3 -3
- package/webpack.config.js +58 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caweb/webpack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "CAWebPublishing Webpack Configuration",
|
|
5
5
|
"main": "webpack.config.js",
|
|
6
6
|
"files": [
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/CAWebPublishing/webpack#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@wordpress/scripts": "^30.
|
|
40
|
+
"@wordpress/scripts": "^30.18.0",
|
|
41
41
|
"css-minimizer-webpack-plugin": "^7.0.2",
|
|
42
42
|
"handlebars-loader": "^1.7.3",
|
|
43
43
|
"html-webpack-link-type-plugin": "^1.1.1",
|
|
44
44
|
"html-webpack-skip-assets-plugin": "^1.0.4",
|
|
45
45
|
"mini-css-extract-plugin": "^2.9.2",
|
|
46
46
|
"rtlcss-webpack-plugin": "^4.0.7",
|
|
47
|
-
"webpack-dev-server": "^5.2.
|
|
47
|
+
"webpack-dev-server": "^5.2.2",
|
|
48
48
|
"webpack-remove-empty-scripts": "^1.1.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
package/webpack.config.js
CHANGED
|
@@ -41,12 +41,32 @@ const appPath = process.cwd();
|
|
|
41
41
|
|
|
42
42
|
// flags can be passed via argv0
|
|
43
43
|
// we also add args from NODE_OPTIONS
|
|
44
|
-
|
|
44
|
+
let flags = [].concat(
|
|
45
45
|
processArgs(process.argv),
|
|
46
46
|
processArgs(process.argv0.split(' ')),
|
|
47
|
-
processArgs(process.env.NODE_OPTIONS ? process.env.NODE_OPTIONS.split(' ') : [])
|
|
47
|
+
processArgs(process.env.NODE_OPTIONS ? process.env.NODE_OPTIONS.split(' ') : []),
|
|
48
48
|
)
|
|
49
49
|
|
|
50
|
+
const cawebJson = fs.existsSync( path.join(appPath, 'caweb.json') ) ?
|
|
51
|
+
JSON.parse(fs.readFileSync(path.join(appPath, 'caweb.json')))
|
|
52
|
+
: {};
|
|
53
|
+
|
|
54
|
+
// we use the caweb.json file to determine the site domain
|
|
55
|
+
if( cawebJson?.site?.domain ){
|
|
56
|
+
let siteDomain = new URL(cawebJson.site.domain);
|
|
57
|
+
|
|
58
|
+
// only add the flags if the site domain is not localhost
|
|
59
|
+
if( 'localhost' !== siteDomain.host ){
|
|
60
|
+
// we add the site domain to the flags
|
|
61
|
+
flags.push(
|
|
62
|
+
`--host`, siteDomain.host,
|
|
63
|
+
'--server-type', siteDomain.protocol.replace(':', ''),
|
|
64
|
+
'--port', '' !== siteDomain.port ? cawebJson.site.port : 80, // default port is 80
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
50
70
|
function processArgs( arr ){
|
|
51
71
|
let tmp = [];
|
|
52
72
|
|
|
@@ -296,7 +316,7 @@ if( 'serve' === webpackCommand ){
|
|
|
296
316
|
let host = flags.includes('--host') ? getArgVal('--host') : 'localhost';
|
|
297
317
|
let port = flags.includes('--port') ? getArgVal('--port') : 9000;
|
|
298
318
|
let server = flags.includes('--server-type') ? getArgVal('--server-type') : 'http';
|
|
299
|
-
|
|
319
|
+
|
|
300
320
|
// Dev Server is added
|
|
301
321
|
webpackConfig.devServer = {
|
|
302
322
|
devMiddleware: {
|
|
@@ -367,10 +387,7 @@ if( 'serve' === webpackCommand ){
|
|
|
367
387
|
|
|
368
388
|
// we add the SERP (Search Engine Results Page)
|
|
369
389
|
// if the caweb.json has a google search id
|
|
370
|
-
if(
|
|
371
|
-
let dataFile = JSON.parse( fs.readFileSync( path.join(appPath, 'caweb.json') ) );
|
|
372
|
-
|
|
373
|
-
if( dataFile.site?.google?.search ){
|
|
390
|
+
if( cawebJson.site?.google?.search ){
|
|
374
391
|
webpackConfig.plugins.push(
|
|
375
392
|
new CAWebHTMLPlugin({
|
|
376
393
|
template: 'search',
|
|
@@ -387,8 +404,41 @@ if( 'serve' === webpackCommand ){
|
|
|
387
404
|
]
|
|
388
405
|
})
|
|
389
406
|
)
|
|
390
|
-
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// we add any additional pages
|
|
410
|
+
let basePageDir = path.join(appPath, 'content', 'pages');
|
|
411
|
+
if( fs.existsSync(basePageDir, {withFileTypes: true} ) ) {
|
|
412
|
+
fs.readdirSync(
|
|
413
|
+
basePageDir,
|
|
414
|
+
{ withFileTypes: true, recursive: true }
|
|
415
|
+
)
|
|
416
|
+
.filter( Dirent => Dirent.isFile() && Dirent.name.endsWith('.html') )
|
|
417
|
+
.map( Dirent => {
|
|
418
|
+
let fileTemplate = path.join(Dirent.parentPath, Dirent.name);
|
|
419
|
+
let p = fs.readFileSync( fileTemplate ).toString();
|
|
420
|
+
let fileName = fileTemplate.replace(basePageDir, '');
|
|
391
421
|
|
|
422
|
+
webpackConfig.plugins.push(
|
|
423
|
+
new CAWebHTMLPlugin({
|
|
424
|
+
template,
|
|
425
|
+
filename: fileName,
|
|
426
|
+
// replace .html, forward slashes with a space, uppercase the first letter of each word, remove Index
|
|
427
|
+
// this is to make sure the title is readable
|
|
428
|
+
// and not just a file name
|
|
429
|
+
title: fileName.replace(/\.html$/, '').replace(/[\/\\]/g, ' ').replace(/\b\w/g, c => c.toUpperCase()).replace(' Index', ''),
|
|
430
|
+
templateParameters: {
|
|
431
|
+
bodyHtmlSnippet: p,
|
|
432
|
+
},
|
|
433
|
+
skipAssets: [
|
|
434
|
+
/.*-rtl.css/, // we skip the Right-to-Left Styles
|
|
435
|
+
/css-audit.*/, // we skip the CSSAudit Files
|
|
436
|
+
/a11y.*/, // we skip the A11y Files
|
|
437
|
+
/jshint.*/, // we skip the JSHint Files
|
|
438
|
+
]
|
|
439
|
+
})
|
|
440
|
+
)
|
|
441
|
+
});
|
|
392
442
|
}
|
|
393
443
|
}
|
|
394
444
|
|