-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
156 lines (151 loc) · 3.99 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const path = require('path');
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DEFAULT_PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || 'localhost';
const PROTOCOL = process.env.HTTPS === 'true' ? 'https' : 'http';
// I am hoping these get cleaned up for webpack 4
// or is no longer needed for a css chunk in the future of webpack
// const ExtractTextPlugin = require('extract-text-webpack-plugin');
// const extractCSS = new ExtractTextPlugin('style.css');
module.exports = ({ prod } = {}) => {
const cssLoaders = [
{
loader: 'css-loader',
options: {
camelCase: true,
importLoaders: 1,
localIdentName: '[name]--[local]--[hash:base64:8]',
modules: true,
sourceMap: !prod,
},
},
'postcss-loader',
];
return {
bail: prod,
devServer: {
contentBase: path.resolve(__dirname, 'public'),
historyApiFallback: true,
host: HOST,
hot: true,
https: PROTOCOL === 'https',
port: DEFAULT_PORT,
publicPath: '/',
},
entry: prod
? ['./src/renderer/index']
: ['react-hot-loader/patch', './src/renderer/index'],
mode: prod ? 'production' : 'development',
module: {
rules: [
{
test: /\.jsx|js($|\?)/,
use: 'babel-loader',
exclude: [path.resolve(__dirname, 'node_modules')],
},
{
test: /\.scss$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
},
{
test: /\.css($|\?)/,
use: ['style-loader', ...cssLoaders],
},
{
test: /\.svg$/,
use: 'raw-loader',
exclude: [
path.resolve(__dirname, 'src/renderer/containers/app/fonts'),
],
},
{
test: /\.(ttf|eot|woff|woff2|svg|png)$/,
use: {
loader: 'file-loader',
},
include: [
path.resolve(__dirname, 'src/renderer/containers/app/fonts'),
],
},
],
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
},
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: true,
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
plugins: [
...(prod
? [
new CopyPlugin([
{
from: path.resolve(__dirname, 'public', '*'),
to: path.resolve(__dirname, 'dist'),
},
]),
]
: [new webpack.HotModuleReplacementPlugin()]),
// extractCSS,
new HtmlWebpackPlugin({
fileName: 'index.html',
template: './src/renderer/index.html',
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new Dotenv({
path: prod
? path.resolve(__dirname, '.env.production')
: path.resolve(__dirname, '.env'),
}),
],
resolve: {
extensions: ['.js', '.jsx', '.json', '.css', '.node'],
alias: {
components: path.resolve(__dirname, 'src', 'renderer', 'components'),
containers: path.resolve(__dirname, 'src', 'renderer', 'containers'),
'redux-middleware': path.resolve(
__dirname,
'src',
'renderer',
'redux',
'middleware'
),
'redux-modules': path.resolve(
__dirname,
'src',
'renderer',
'redux',
'modules'
),
root: __dirname,
scenes: path.resolve(__dirname, 'src', 'renderer', 'scenes'),
src: path.resolve(__dirname, 'src'),
test: path.resolve(__dirname, 'test'),
},
},
target: 'web',
};
};