-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
103 lines (90 loc) · 2.49 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
101
102
103
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const webpack = require("webpack");
const project = "./src/Client/Client.fsproj";
const style = "./src/Client/Style/style.sass";
const assetsDir = "src/Client/assets";
const htmlWebpackPlugin = new HtmlWebpackPlugin({
filename: "index.html",
template: "src/Client/index.html"
});
const babel = {
presets: [
[ "@babel/preset-env", { modules: false, useBuiltIns: "usage", corejs: 3 } ]
]
};
module.exports = env => ({
mode: env.production ? "production" : "development",
entry: env.production
// Combine code and style because MiniCssExtractPlugin will separate them.
? { app: [ project, style ] }
// Separate code and style for faster HMR.
: { app: [ project ], style: [ style ] },
output: {
path: path.resolve("src/Client/deploy"),
filename: env.production ? "[name].[contenthash].js" : "[name].js",
publicPath: "/"
},
optimization: {
splitChunks: { chunks: "all" }
},
plugins: env.production
? [ htmlWebpackPlugin,
new MiniCssExtractPlugin({ filename: "style.[contenthash].css" }),
new CopyWebpackPlugin({ patterns: [ { from: assetsDir } ] }) ]
: [ htmlWebpackPlugin,
new webpack.HotModuleReplacementPlugin() ],
devtool: env.production ? "source-map" : "eval-source-map",
devServer: {
host: "0.0.0.0",
port: 8080,
publicPath: "/",
contentBase: assetsDir,
hot: true,
inline: true,
historyApiFallback: { index: "/" },
proxy: {
"/socket": {
target: "http://localhost:8085",
ws: true
}
}
},
module: {
rules: [
{
test: /\.fs(x|proj)?$/,
use: {
loader: "fable-loader",
options: { babel }
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: babel
},
},
{
test: /\.(sass|scss|css)$/,
use: [
env.production ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"resolve-url-loader",
{
loader: "sass-loader",
options: { implementation: require("sass") }
}
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*)?$/,
use: [ "file-loader" ]
}
]
}
});