-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
95 lines (90 loc) · 2.78 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
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CONFIG = {
indexHtmlTemplate: 'public/index.html',
fsharpEntry: 'docs/App.fsproj',
outputDir: 'public',
devServerPort: 8080,
// Use babel-preset-env to generate JS compatible with most-used browsers.
// More info at https://babeljs.io/docs/en/next/babel-preset-env.html
babel: {
presets: [
['@babel/preset-env', {
modules: false,
// This adds polyfills when needed. Requires core-js dependency.
// See https://babeljs.io/docs/en/babel-preset-env#usebuiltins
// Note that you still need to add custom polyfills if necessary (e.g. whatwg-fetch)
useBuiltIns: 'usage',
corejs: 3
}]
],
}
}
// If we're running the webpack-dev-server, assume we're in development mode
var isProduction = !process.argv.find(v => v.indexOf('webpack-dev-server') !== -1);
console.log('Bundling for ' + (isProduction ? 'production' : 'development') + '...');
var commonPlugins = [
new HtmlWebpackPlugin({
filename: 'index.html',
template: resolve(CONFIG.indexHtmlTemplate)
})
];
module.exports = {
entry: resolve(CONFIG.fsharpEntry),
output: {
path: resolve(CONFIG.outputDir),
filename: 'bundle.[hash].js',
},
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? 'source-map' : 'eval-source-map',
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all'
},
},
plugins: isProduction ?
commonPlugins.concat([])
: commonPlugins.concat([
new webpack.HotModuleReplacementPlugin()
]),
resolve: {
// See https://github.com/fable-compiler/Fable/issues/1490
symlinks: false
},
devServer: {
contentBase: CONFIG.outputDir,
hot: true,
inline: true,
port: CONFIG.devServerPort
},
module: {
rules: [
{
test: /\.fs(x|proj)?$/,
use: {
loader: 'fable-loader',
options: {
define: isProduction ? [] : ['DEBUG']
}
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: CONFIG.babel
}
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot|md)(\?.*)?$/,
use: ['file-loader']
}
]
}
};
function resolve(filePath) {
return path.join(__dirname, filePath);
}