-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.development.js
More file actions
109 lines (106 loc) · 2.58 KB
/
webpack.development.js
File metadata and controls
109 lines (106 loc) · 2.58 KB
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
const webpack = require('webpack');
const path = require('path');
const Dotenv = require('dotenv-webpack');
const nodeExternals = require('webpack-node-externals');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
const client = {
name: 'client',
target: 'web',
entry: './src/client/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js'
},
devtool: 'inline-source-map',
devServer: {
port: 8081,
historyApiFallback: true,
hot: true
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
// Loads the javacript into html template provided.
// Entry point is set below in HtmlWebPackPlugin in Plugins
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|svg|jpg|gif)$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets'
}
}
}
]
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.jsx', '.json']
},
plugins: [
new HtmlWebPackPlugin({
template: 'src/client/index.html',
alwaysWriteToDisk: true, // prevents webpack error 'no such file or directory' for in-memory index.html
filename: './index.html',
excludeChunks: ['server']
}),
new HtmlWebpackHarddiskPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new Dotenv({
path: '.env.development'
})
]
};
const server = {
name: 'server',
target: 'node',
entry: ['webpack/hot/poll?1000', './src/server/server-dev.js'],
output: {
path: path.resolve(__dirname, 'build'),
filename: 'server.js'
},
cache: false,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules']
},
externals: [nodeExternals({ allowlist: ['webpack/hot/poll?1000'] })],
plugins: [
new Dotenv({
path: '.env.development'
}),
new webpack.HotModuleReplacementPlugin()
]
};
module.exports = [client, server];