This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
82 lines (72 loc) · 2.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const HandlebarsPlugin = require("handlebars-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const path = require("path")
module.exports = {
mode: "production",
output: {
path: __dirname,
filename: "app.bundle.js",
publicPath: "/"
},
devtool: "source-map",
module: {
rules: [
{
test: /\.hbs$/,
loader: "handlebars-loader",
options: {
helperDirs: path.resolve(__dirname, "src", "helpers-hbs"),
partialDirs: [
path.resolve(__dirname, "src", "components"),
]
}
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"],
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css"
}),
new HandlebarsPlugin({
entry: path.join(__dirname, "src", "*.hbs"),
// output path and filename(s). This should lie within the webpacks output-folder
// if ommited, the input filepath stripped of its extension will be used
output: path.join(__dirname, "[name].html"),
// you can also add a [path] variable, which will emit the files with their relative path, like
// output: path.join(process.cwd(), "build", [path], "[name].html"),
// data passed to main hbs template: `main-template(data)`
// data: require("./app/data/project.json"),
// or add it as filepath to rebuild data on change using webpack-dev-server
data: path.join(__dirname, "cases.json"),
// globbed path to partials, where folder/filename is unique
partials: [
path.join(__dirname, "src", "components", "*.hbs")
],
// register custom helpers. May be either a function or a glob-pattern
helpers: {
projectHelpers: path.join(__dirname, "src", "helpers", "*.helper.js")
},
// hooks
// getTargetFilepath: function (filepath, outputTemplate) {},
// getPartialId: function (filePath) {}
onBeforeSetup: function (Handlebars) {},
onBeforeAddPartials: function (Handlebars, partialsMap) {},
onBeforeCompile: function (Handlebars, templateContent) {},
onBeforeRender: function (Handlebars, data, filename) {},
onBeforeSave: function (Handlebars, resultHtml, filename) {},
onDone: function (Handlebars, filename) {}
}),
],
devServer: {
contentBase: __dirname,
compress: true,
port: 3000,
open: true,
publicPath: "/",
historyApiFallback: true
}
}