-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
129 lines (121 loc) · 3.15 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const path = require("path");
const webpack = require("webpack");
const fableUtils = require("fable-utils");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
function resolve(filePath) {
return path.join(__dirname, filePath)
}
var babelOptions = fableUtils.resolveBabelOptions({
presets: [
["env", {
"targets": {
"browsers": ["last 2 versions"]
},
"modules": false
}],
],
});
var commonPlugins = [
new HtmlWebpackPlugin({
filename: resolve('./build/js/index.html'),
template: resolve('./src/index.html')
})
];
var isProduction = process.argv.indexOf("-p") >= 0;
console.log("Bundling for " + (isProduction ? "production" : "development") + "...");
module.exports = (env, argv) => ({
mode: isProduction ? "production" : "development",
devtool: isProduction ? false : 'source-map',
entry: resolve('./src/Parsec.fsproj'),
output: {
path: resolve('./build/js'),
filename: isProduction ? '[name].[hash].js' : '[name].js'
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
},
fable: {
test: /[\\/]fable-core[\\/]/,
name: 'fable',
chunks: 'all'
}
}
}
},
plugins: isProduction ?
commonPlugins.concat([
new ExtractTextPlugin('style.[contenthash].css'),
new CopyWebpackPlugin([
{ from: './src' }
]),
// ensure that we get a production build of any dependencies
// this is primarily for React, where this removes 179KB from the bundle
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
})
])
: commonPlugins.concat([
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
]),
resolve: {
modules: [
"node_modules", resolve("./node_modules/")
]
},
devServer: {
//contentBase: resolve('./public/'),
publicPath: "/",
port: 8080,
hot: true,
inline: true
},
module: {
rules: [
{
test: /\.fs(x|proj)?$/,
use: {
loader: "fable-loader",
options: {
babel: babelOptions,
define: isProduction ? [] : ["DEBUG"],
extra: { optimizeWatch: true }
}
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: babelOptions
},
},
{
test: /\.s(a|c)ss$/,
use: isProduction ?
ExtractTextPlugin.extract({
fallback: 'style-loader',
//resolve-url-loader may be chained before sass-loader if necessary
use: ['css-loader', 'sass-loader']
})
: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
use: ["file-loader"]
}
]
}
});