generated from mearns/node-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
79 lines (73 loc) · 1.98 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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const packageInfo = require("./package.json");
const webpack = require("webpack");
const APP_NAME = packageInfo.name;
const babelLoader = {
loader: "babel-loader",
options: {
presets: [
["@babel/preset-env", { targets: "> 0.25%, not dead" }],
"@babel/preset-react"
],
plugins: ["@babel/transform-runtime"]
}
};
const config = {
entry: {},
output: {
path: path.resolve(__dirname, "dist/bundles"),
filename: "[name].[chunkhash].js",
publicPath: "/static/bundles"
},
module: {
rules: [
{
test: /\.html$/,
use: [
"file-loader?name=../pages/[name].[ext]",
"extract-loader",
"html-loader"
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: babelLoader
}
]
},
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: "[name]-bundle.map",
append: "\n//# sourceMappingURL=[url]",
moduleFilenameTemplate: `${APP_NAME}:///[resource-path]`
})
],
watch: true
};
/**
* Add a page that will be served as a boilerplate HTML document
* that serves up the given javascript file as a client-side script.
* The client-side script runs at the end of page load.
*/
function addClientSideScript(name, scriptPath) {
config.entry[name] = [
path.resolve(
__dirname,
"node_modules",
"source-map-support",
"register.js"
),
scriptPath
];
config.plugins.push(
new HtmlWebpackPlugin({
chunks: [name],
filename: `../pages/${name}.html`,
title: name
})
);
}
addClientSideScript("index", "./src/pages/index.js");
module.exports = config;