-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
79 lines (68 loc) · 2.1 KB
/
webpack.config.js
File metadata and controls
79 lines (68 loc) · 2.1 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
//todo: https://github.com/webpack-contrib/mini-css-extract-plugin
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const BUILD_PATH = path.resolve(__dirname, 'build');
module.exports = {
entry: './src/index.js',
output: {
filename: '[name].[hash].js',
path: BUILD_PATH,
},
resolve: {
extensions: ['.js'],
modules: [path.join(process.cwd(), 'src'), 'node_modules'], // include imported modules
},
module: {
rules: [{
// eslint-loader
enforce: 'pre', // force source files untouced by other loaders
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
}, {
// css-loader
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
}, {
// file-loader
test: /\.(png|svg|jpg|gif)$/,
use: [ 'file-loader' ],
}],
},
devtool: "source-map",
devServer: {
port: 3008,
open: true,
hot: true,
devMiddleware: {
stats: {
// minimal output on development terminal, show eslint errors and warns, surpress other stats
assets: false,
children: false,
modules: false,
},
},
},
plugins: [
// clean up build folder
new CleanWebpackPlugin({
root: process.cwd(),
}),
// parse and copy index.html
new HtmlWebpackPlugin({
inject: 'head', // all javascript resources will be placed in <head> (default: bottom body)
template: path.resolve(__dirname, 'src') + '/index.html',
}),
// hmr
new webpack.HotModuleReplacementPlugin(),
// copy static
new CopyWebpackPlugin({
patterns: [
{ from: 'static/**/*', to: BUILD_PATH },
],
}),
]
};