@caweb/webpack 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/webpack.config.js +28 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/webpack",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "CAWebPublishing Webpack Configuration",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -44,7 +44,7 @@
44
44
  "dependencies": {
45
45
  "@caweb/a11y-webpack-plugin": "^1.0.2",
46
46
  "@caweb/css-audit-webpack-plugin": "^1.0.2",
47
- "@caweb/html-webpack-plugin": "^1.0.1",
47
+ "@caweb/html-webpack-plugin": "^1.0.2",
48
48
  "@caweb/jshint-webpack-plugin": "^1.0.3",
49
49
  "@wordpress/scripts": "^28.3.0",
50
50
  "html-webpack-plugin": "^5.6.0",
package/webpack.config.js CHANGED
@@ -69,7 +69,30 @@ let webpackConfig = {
69
69
  */
70
70
  {
71
71
  test: /\.html$/,
72
- loader: 'handlebars-loader'
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
+
79
+ // template parameter specific partials
80
+ switch( partial ){
81
+ case 'content': // content is served from the /sample/index.html
82
+ partialPath = fs.existsSync(path.join( partialPath, '/index.html' )) ? path.join( partialPath, '/index.html' ) :
83
+ './missing/content.html';
84
+
85
+ break;
86
+
87
+ // if not a template parameter we let the loader handle it
88
+ default:
89
+ partialPath = partial;
90
+ }
91
+
92
+
93
+ callback(false, partialPath );
94
+ }
95
+ }
73
96
  }
74
97
  ]
75
98
  },
@@ -84,13 +107,7 @@ let webpackConfig = {
84
107
  */
85
108
  if( 'serve' === webpackCommand ){
86
109
  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');
110
+ const samplePath = path.join( appPath, 'sample');
94
111
 
95
112
  // Dev Server is added
96
113
  webpackConfig.devServer = {
@@ -149,7 +166,7 @@ if( 'serve' === webpackCommand ){
149
166
  let pageTemplate = {
150
167
  title : path.basename(appPath),
151
168
  filename: path.join( appPath, 'public', 'index.html'),
152
- template: path.join(samplePath, 'index.html'),
169
+ template: path.join( appPath, 'node_modules', '@caweb', 'html-webpack-plugin', 'sample', 'index.html'),
153
170
  favicon: fs.existsSync(path.join(samplePath, 'favicon.ico')) ? path.join(samplePath, 'favicon.ico') : false,
154
171
  minify: false,
155
172
  scriptLoading: 'blocking',
@@ -161,7 +178,8 @@ if( 'serve' === webpackCommand ){
161
178
  "viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
162
179
  },
163
180
  templateParameters: {
164
- "title" : path.basename(appPath)
181
+ "title" : path.basename(appPath),
182
+ "content": '/sample/index.html'
165
183
  },
166
184
  skipAssets: [
167
185
  '**/*-rtl.css', // we skip the Right-to-Left Styles