-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
115 lines (103 loc) · 3.23 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
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
function resolve(filePath) {
return path.isAbsolute(filePath) ? filePath : path.join(__dirname, filePath);
}
var cfg = {
projectPath: './src/Demo/',
index: './src/Demo/index.html',
entry: './fable_output/Main.js',
output: './dist'
}
// CopyWebpackPlugin format
cfg.copy = [
'public',
'node_modules/bulma/css/bulma.min.css',
{
from: 'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
to: 'fa/css/[name][ext]'
},
{
from: 'node_modules/@fortawesome/fontawesome-free/webfonts/*',
to: 'fa/webfonts/[name][ext]'
}
]
// The HtmlWebpackPlugin allows us to use a template for the index.html page
// and automatically injects <script> or <link> tags for generated bundles.
var htmlPlugin =
new HtmlWebpackPlugin({
filename: 'index.html',
template: resolve(cfg.index)
});
// Copies static assets to output directory
var copyPlugin =
new CopyWebpackPlugin({
patterns: cfg.copy
});
// CSS bundling
var cssPlugin =
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
});
// Configuration for webpack-dev-server
var devServer = {
host: 'localhost',
port: 8888,
hot: true,
// hot: false,
// liveReload: false,
client: {overlay: false}
};
// 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);
var environment = isProduction ? 'production' : 'development';
process.env.NODE_ENV = environment;
console.log('Bundling for ' + environment + '...');
module.exports = {
entry: { app: resolve(cfg.entry) },
output: {
path: resolve(cfg.output),
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
clean: true
},
devtool: isProduction ? undefined : 'eval-source-map',
resolve: {
alias: {
Project: path.resolve(__dirname, cfg.projectPath)
},
symlinks: false
}, // See https://github.com/fable-compiler/Fable/issues/1490
mode: environment,
plugins: isProduction ? [cssPlugin, htmlPlugin, copyPlugin] : [htmlPlugin, copyPlugin],
optimization: { splitChunks: { chunks: 'all' } },
devServer: devServer,
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
exclude: /node_modules|fable_modules/,
use: ["source-map-loader"]
},
{
test: /\.(sass|scss|css)$/,
use: [
isProduction
? MiniCssExtractPlugin.loader
: 'style-loader',
{
loader: 'css-loader',
// otherwise it breaks css urls
options: {url: false}
},
]
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*)?$/,
use: ['file-loader']
}
]
}
};