-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (78 loc) · 4.45 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
83
84
85
86
87
const path = require('path');
const HandlebarsPlugin = require("handlebars-webpack-plugin");
const moveFile = require('move-file');
const bundleFileName = 'bundle';
const distPath = path.resolve(__dirname);
const jsDirName = 'assets/js';
const jsDistPath = path.resolve(__dirname, jsDirName);
const packageVersion = require('./package.json').version || '1.0.0';
const moveNonHtmlHandlebarGeneratedFile = (filename, handlebarFilename, newName) => {
const newFileName = (newName != null) ? `${distPath}/${newName}` : `${distPath}/${filename}`;
if (handlebarFilename.includes(`${filename}.html`)) {
moveFile(`${distPath}/${filename}.html`, newFileName)
.then(() => console.log(`The ${filename} file has been renamed`))
.catch(() => console.error(`The ${filename} file was NOT renamed`));
}
}
module.exports = (env, argv) => {
return {
mode: argv.mode === "production" ? "production" : "development",
entry: [
'./webpack/lib/custom.js',
],
output: {
filename: bundleFileName + '.js',
path: jsDistPath,
library: 'KurtLourens',
// libraryTarget: 'window'
},
plugins: [
new HandlebarsPlugin({
// path to hbs entry file(s). Also supports nested directories if write path.join(process.cwd(), "app", "src", "**", "*.hbs"),
entry: path.join(process.cwd(), "webpack", "handlebar", "*.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(distPath, "[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("./webpack/data/project.json"),
// or add it as filepath to rebuild data on change using webpack-dev-server
data: path.join(__dirname, "webpack/data/project.json"),
// globbed path to partials, where folder/filename is unique
partials: [
path.join(process.cwd(), "webpack", "handlebar", "*", "*.hbs")
],
// register custom helpers. May be either a function or a glob-pattern
helpers: {
nameOfHbsHelper: Function.prototype,
sectionclass: require("./webpack/handlebar/helpers/sectionclass.helper"),
urlref: require("./webpack/handlebar/helpers/urlref.helper"),
loud: require("./webpack/handlebar/helpers/loud.helper"),
date: require("./webpack/handlebar/helpers/date.helper"),
handleshortcode: require("./webpack/handlebar/helpers/shortcode.helper"),
workitemclass: require("./webpack/handlebar/helpers/workitemclass.helper"),
version: require("./webpack/handlebar/helpers/version.helper")(packageVersion)
},
// 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) {
moveNonHtmlHandlebarGeneratedFile('web.config', filename);
moveNonHtmlHandlebarGeneratedFile('htaccess', filename, '.htaccess');
moveNonHtmlHandlebarGeneratedFile('sitemap.xml', filename);
moveNonHtmlHandlebarGeneratedFile('opensearch.xml', filename);
moveNonHtmlHandlebarGeneratedFile('humans.txt', filename);
moveNonHtmlHandlebarGeneratedFile('manifest.json', filename);
moveNonHtmlHandlebarGeneratedFile('site.webmanifest', filename);
moveNonHtmlHandlebarGeneratedFile('robots.txt', filename);
}
}),
],
};
};