-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
100 lines (95 loc) · 2.53 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
98
99
100
const { TsConfigPathsPlugin } = require("awesome-typescript-loader")
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin
const CleanWebpackPlugin = require("clean-webpack-plugin")
const CopyWebpackPlugin = require("copy-webpack-plugin")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const webpack = require("webpack")
const path = require("path")
const sourcePath = path.join(__dirname, "./src")
const outPath = path.join(__dirname, "./public")
const includePaths = [path.join(__dirname, "./src")]
module.exports = function(env) {
const plugins = [
new CleanWebpackPlugin(["public"]),
new CopyWebpackPlugin([{ from: "assets", to: "" }]),
new HtmlWebpackPlugin({
filename: "./index.html",
template: "./src/index.html"
})
]
let main
if (env.build) {
plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: "static",
openAnalyzer: false,
reportFilename: "../reports/report.html"
})
)
main = "./src/index.prod.ts"
} else {
main = "./src/index.dev.ts"
}
const configs = require("./config/" + env.target)
plugins.push(new webpack.DefinePlugin(configs))
return {
mode: env.build ? "production" : "development",
devtool: env.build ? undefined : "inline-source-map",
context: __dirname,
entry: {
main
},
output: {
path: outPath,
publicPath: "/",
filename: "bundle.[hash].js"
},
plugins: plugins,
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
plugins: [new TsConfigPathsPlugin()]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: ["awesome-typescript-loader"],
include: includePaths
},
{
test: /\.jsx?$/,
use: ["awesome-typescript-loader"],
include: includePaths
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
externals: {
firebase: "firebase",
firebaseui: "firebaseui",
rollup: "rollup",
typescript: "ts",
// actual name not needed, just that this is an external and it exists
"monaco-editor": "firebase",
vs: "vs"
},
devServer: {
contentBase: path.join(__dirname, "public"),
compress: false,
port: 3000,
historyApiFallback: true
},
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
}
}