-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
78 lines (67 loc) · 1.74 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
require('dotenv').config()
const { resolve } = require('path')
const webpack = require('webpack')
const CleanPlugin = require('clean-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const assetsPath = resolve(__dirname, './public/dist')
const port = parseInt(process.env.PORT) + 1
const config = {
entry: {
app: './client/index.js'
},
output: {
path: assetsPath,
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: '/dist/',
},
module: {
rules: [
{
test: /\.(jpg|png|svg|otf|ttf|eot|woff(2)?)(\?v=\d+\.\d+\.\d+)?$/,
include: [resolve('./public'), resolve('./node_modules')],
loader: 'url-loader',
options: { limit: 10240, name: '[name].[ext]' }
},
{
test: /\.js$/,
include: resolve('./client'),
loader: 'babel-loader',
options: { cacheDirectory: true }
}
]
},
plugins: [
new webpack.EnvironmentPlugin({
PUBLIC_URL: null
}),
new ManifestPlugin({ writeToFileEmit: true })
],
resolve: {
modules: [
'client',
'node_modules'
]
},
devServer: {
port,
allowedHosts: ['localhost', '.lvh.me'],
hot: true,
hotOnly: true,
headers: {
'Access-Control-Allow-Origin': '*',
}
}
}
module.exports = (env, argv) => {
if (argv.mode !== 'production') {
config.devtool = 'cheap-module-source-map'
config.output.publicPath = `${process.env.PUBLIC_URL}:${port}/dist/`
config.plugins.push(new webpack.HotModuleReplacementPlugin())
} else {
config.output.filename = '[name]-[hash].js'
config.output.chunkFilename = '[name]-[hash].js'
config.plugins.push(new CleanPlugin([assetsPath], { verbose: false }))
}
return config
}