-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
83 lines (75 loc) · 1.85 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
var path = require("path");
var webpack = require("webpack");
var merge = require('webpack-merge');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
const prod = 'production';
const dev = 'development';
// determine build env
const TARGET_ENV = process.env.npm_lifecycle_event === 'build' ? prod : dev;
const isDev = TARGET_ENV == dev;
const isProd = TARGET_ENV == prod;
const entryPath = "./src/app.js"
console.log("WEBPACK STARTED")
console.log("Building for", TARGET_ENV)
var commonConfig = {
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].bundle.js',
},
module: {
noParse: /\.elm$/,
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: 'src/index.html',
inject: 'body',
filename: 'index.html',
})
],
};
if (isDev) {
module.exports = merge(commonConfig, {
entry: [
'webpack-dev-server/client?http://localhost:8080',
entryPath
],
devServer: {
contentBase: './src/',
},
module: {
rules: [{
test: /\.elm$/,
exclude: [/elm-suff/, /node_modules/],
loader: 'elm-webpack-loader',
options: {
debug: true
}
},{
test: /\.sc?ss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}]
}
});
}
if (isProd) {
module.exports = merge(commonConfig, {
entry: entryPath,
module: {
rules: [{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: 'elm-webpack-loader',
}, {
test: /\.sc?ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
}]
},
plugins: [new MiniCssExtractPlugin()],
optimization: {
minimize: true
}
});
}