-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
58 lines (54 loc) · 1.77 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict'
const path = require('path')
, HandlebarsPlugin = require('handlebars-webpack-plugin')
, config = require('./config.json')
const appRoot = path.resolve(__dirname)
, hbx = require('HandlebarsExtended')({ appRoot, ...config.paths })
module.exports = {
// mode: 'development', devtool: false,
mode : 'production',
entry : {
site : './src/js/site.js',
formevents : './src/js/formevents.js',
workshops : './src/js/workshops.js'
},
output : {
filename : '[name].js',
path : path.join(__dirname, config.paths.outputBuildPath, 'js')
},
plugins : [
new HandlebarsPlugin({
entry : path.join(__dirname, 'src', 'view', 'page', '**', '*.hbs'),
output : path.join(__dirname, config.paths.outputBuildPath, '[path]', '[name]'),
data : config,
// globbed path to partials, where folder/filename is unique
partials : [
path.join(appRoot, 'src', 'view', 'component', '*', '*.hbs')
],
// register custom helpers
helpers : {
wrap : hbx.helpers.wrap,
include : hbx.helpers.include,
math : hbx.helpers.math
},
onBeforeRender : (hb, data, filename) => {
let controllereData = {}
try {
const controllerName = filename
.replace(/(\..*)?\.hbs$/, '') // strip .hbs or .ext.hbs extension
.replace(config.paths.pagesPath, config.paths.controllerPath) // change to controller path
controllereData = require(controllerName)
} catch (e) {}
const filenameNoExt = path.parse(path.basename(filename, '.hbs')).name
return {
pagename : {
name : filenameNoExt,
is : { [filenameNoExt] : true }
},
...data,
...controllereData
}
}
})
]
}