@caweb/webpack 1.6.5 → 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.
@@ -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/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: {
@@ -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('--mode') ? getArgVal('--mode') : baseConfig.mode;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/webpack",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "CAWebPublishing Webpack Configuration",
5
5
  "main": "webpack.config.js",
6
6
  "files": [
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 { flags, flagExists, getArgVal, addFlag } from './lib/args.js';
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