-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
97 lines (95 loc) · 2.52 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
88
89
90
91
92
93
94
95
96
97
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const webpack = require("webpack");
const webpackMerge = require("webpack-merge");
const HtmlWebpackInlineSourcePlugin = require("html-webpack-inline-source-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const modeConfig = (env, platform) =>
require(`./build-utils/webpack.${env}`)(env, platform);
module.exports = (
env = {
mode: "production",
platform: "web"
}
) => {
return webpackMerge(
{
mode: env.mode,
entry: {
web: ["babel-polyfill", "./src/web-app/index.js"],
local: ["babel-polyfill", "./src/local-app/index.js"]
},
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].js"
},
plugins: [
new Dotenv({
path: `./${env.mode}.env` // load this now instead of the ones in '.env'
}),
new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({
filename: "local-setup-file.html",
template: "./public/local-setup-file.html",
chunks: ["local"],
inlineSource: ".(js|css)$"
}),
new HtmlWebpackInlineSourcePlugin(HtmlWebpackPlugin),
new HtmlWebpackPlugin({
filename: "index.html",
template: "./public/index.html",
chunks: ["web"],
minify: true
}),
new CopyWebpackPlugin([
// relative path is from src
{ from: "./public/favicon.ico" }
])
],
module: {
rules: [
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.(png|jpg|jpeg|gif)$/i,
use: [
{
loader: "url-loader",
options: {
limit: 8192
}
}
]
},
{
test: /\.(woff(2)?|ttf|eot|svg|otf)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "fonts/"
}
}
]
}
]
}
},
modeConfig(env.mode, env.platform)
);
};