@caweb/webpack 1.6.4 → 1.6.6
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/helpers/string/replace.js +1 -1
- package/lib/handlebars.js +69 -0
- package/lib/loader.js +1 -0
- package/lib/server.js +11 -0
- package/lib/webpack.wp.config.js +1 -1
- package/package.json +1 -1
- package/tests/webpack.tests.js +4 -4
- package/webpack.config.js +2 -1
|
@@ -7,7 +7,7 @@ export default function replace(value, search, replace, options){
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// if nested content exists
|
|
10
|
-
if( value.fn && value.fn().length ){
|
|
10
|
+
if( value && value.fn && value.fn().length ){
|
|
11
11
|
response += value.fn().replace(new RegExp(search, "g"), replace);
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// This handlebars assumes we are using the @caweb/template as the fallback for any partials that are not found in the application. This allows us to use the default template partials without having to copy them into the application. It also allows us to use any custom partials that the application may have without having to worry about them being overwritten by the default template partials.
|
|
2
|
+
import Handlebars from 'handlebars';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
|
|
8
|
+
const currentPath = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
|
|
11
|
+
let appPath = process.cwd();
|
|
12
|
+
let fallbackPath = path.join(appPath, 'node_modules', '@caweb', 'template');
|
|
13
|
+
|
|
14
|
+
let templatePartials = {
|
|
15
|
+
'branding': 'semantics/branding.html',
|
|
16
|
+
'footer': 'semantics/footer.html',
|
|
17
|
+
'header': 'semantics/header.html',
|
|
18
|
+
'mobileControls': 'semantics/mobile-controls.html',
|
|
19
|
+
'navFooter': 'semantics/nav-footer.html',
|
|
20
|
+
'navHeader': 'semantics/nav-header.html',
|
|
21
|
+
'utilityHeader': 'semantics/utility-header.html',
|
|
22
|
+
'head': 'semantics/head.html',
|
|
23
|
+
'alert': 'components/alert/alert.html',
|
|
24
|
+
'searchForm': 'forms/search.html'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Register partials.
|
|
28
|
+
Object.entries(templatePartials).forEach(
|
|
29
|
+
([p, f]) => {
|
|
30
|
+
let partial = false;
|
|
31
|
+
|
|
32
|
+
// if the application has a partial with the same name as the template partials we use that instead of the default template partial
|
|
33
|
+
if( fs.existsSync( path.join(appPath, f) ) ){
|
|
34
|
+
partial = path.join(appPath, f);
|
|
35
|
+
// the fallback path exists we use that
|
|
36
|
+
} else if( fs.existsSync( path.join(fallbackPath, f) ) ){
|
|
37
|
+
partial = path.join(fallbackPath, f);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if( partial ) {
|
|
41
|
+
Handlebars.registerPartial(p, fs.readFileSync(partial).toString() );
|
|
42
|
+
}
|
|
43
|
+
} );
|
|
44
|
+
|
|
45
|
+
// Register helpers.
|
|
46
|
+
fs.readdirSync( path.join(currentPath, '..', 'helpers'), { recursive:true } )
|
|
47
|
+
.filter( (file) => file.endsWith('.js') )
|
|
48
|
+
.filter( Boolean )
|
|
49
|
+
.map( (file) => {
|
|
50
|
+
let name = path.basename(file).replace('.js', '');
|
|
51
|
+
let helper = require( path.join(currentPath, '..', 'helpers', file) ).default;
|
|
52
|
+
|
|
53
|
+
Handlebars.registerHelper( name, helper );
|
|
54
|
+
} );
|
|
55
|
+
|
|
56
|
+
// Register customer helpers from the application if they exist.
|
|
57
|
+
if( fs.existsSync( path.join(appPath, 'helpers') ) ){
|
|
58
|
+
fs.readdirSync( path.join(appPath, 'helpers'), { recursive:true } )
|
|
59
|
+
.filter( (file) => file.endsWith('.js') )
|
|
60
|
+
.filter( Boolean )
|
|
61
|
+
.map( (file) => {
|
|
62
|
+
let name = path.basename(file).replace('.js', '');
|
|
63
|
+
let helper = require( path.join(appPath, 'helpers', file) ).default;
|
|
64
|
+
|
|
65
|
+
Handlebars.registerHelper( name, helper );
|
|
66
|
+
} );
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default Handlebars;
|
package/lib/loader.js
CHANGED
package/lib/server.js
CHANGED
|
@@ -97,6 +97,17 @@ let devServer = {
|
|
|
97
97
|
liveReload: true,
|
|
98
98
|
hot: true,
|
|
99
99
|
|
|
100
|
+
historyApiFallback: {
|
|
101
|
+
rewrites: [
|
|
102
|
+
// Rewrite any request that doesn't have a file extension to your 404 page
|
|
103
|
+
// This is a simple regex; adjust as needed
|
|
104
|
+
{
|
|
105
|
+
from: /^\/.*[^.][^/]*$/, // Matches paths without file extensions
|
|
106
|
+
to: '/404.html',
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
|
|
100
111
|
// watchFiles
|
|
101
112
|
// we watch all folders in the app except build, node_modules and src
|
|
102
113
|
watchFiles: {
|
package/lib/webpack.wp.config.js
CHANGED
|
@@ -18,7 +18,7 @@ import { getArgVal } from './args.js';
|
|
|
18
18
|
// Wordpress ignores the webpack --mode flag
|
|
19
19
|
// if the flag is passed we use that mode
|
|
20
20
|
// otherwise use whatever Wordpress is using
|
|
21
|
-
let mode = getArgVal('
|
|
21
|
+
let mode = getArgVal('mode') ? getArgVal('mode') : baseConfig.mode;
|
|
22
22
|
let isProduction = mode === 'production';
|
|
23
23
|
|
|
24
24
|
// Update some of the default WordPress webpack rules.
|
package/package.json
CHANGED
package/tests/webpack.tests.js
CHANGED
|
@@ -35,10 +35,10 @@ JSON.parse(fs.readFileSync(path.join(appPath, 'caweb.json')))
|
|
|
35
35
|
let caweb = deepmerge( testCaweb, defaultCaweb );
|
|
36
36
|
|
|
37
37
|
let templatePath = path.join(appPath, 'node_modules', '@caweb', 'template');
|
|
38
|
-
let template = getArgVal( '
|
|
39
|
-
let searchTemplate = getArgVal( '
|
|
38
|
+
let template = getArgVal( 'template', path.join(templatePath, 'patterns', 'default.html') );
|
|
39
|
+
let searchTemplate = getArgVal( 'search-template', path.join(templatePath, 'patterns', 'search.html') );
|
|
40
40
|
|
|
41
|
-
let scheme = getArgVal( '
|
|
41
|
+
let scheme = getArgVal( 'scheme', 'oceanside' );
|
|
42
42
|
let favicon = caweb?.site?.favicon ?? null;
|
|
43
43
|
|
|
44
44
|
// // Additional pages directory
|
|
@@ -65,7 +65,7 @@ let additionalPages = ! fs.existsSync( basePageDir ) ? [] :
|
|
|
65
65
|
|
|
66
66
|
return new HtmlWebpackPlugin({
|
|
67
67
|
template,
|
|
68
|
-
filename:
|
|
68
|
+
filename: fileTemplate.replace(basePageDir, ''),
|
|
69
69
|
title,
|
|
70
70
|
templateParameters: {
|
|
71
71
|
...caweb.site, // we spread the site data found in the caweb.json file
|
package/webpack.config.js
CHANGED
|
@@ -31,7 +31,7 @@ import {HtmlWebpackSkipAssetsPlugin} from 'html-webpack-skip-assets-plugin';
|
|
|
31
31
|
/**
|
|
32
32
|
* Internal dependencies
|
|
33
33
|
*/
|
|
34
|
-
import {
|
|
34
|
+
import { getArgVal } from './lib/args.js';
|
|
35
35
|
import handlebarsLoaderOptions from './lib/loader.js';
|
|
36
36
|
import { addToServer, getServer, updateTarget } from './lib/server.js';
|
|
37
37
|
|
|
@@ -103,6 +103,7 @@ let webpackConfig = {
|
|
|
103
103
|
chunkFilename: isProduction ? '[name].min.js?v=[chunkhash]' : '[name].js?v=[chunkhash]',
|
|
104
104
|
pathinfo: false,
|
|
105
105
|
clean: isProduction,
|
|
106
|
+
publicPath: '/',
|
|
106
107
|
},
|
|
107
108
|
|
|
108
109
|
/**
|