-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.js
116 lines (112 loc) · 2.93 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
const Path = require('path')
const webpack = require('webpack')
const WebpackNotifierPlugin = require('webpack-notifier')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const env = process.env.NODE_ENV
const plugins = [
new webpack.DefinePlugin({
SERVER_URL: env === 'production'
? '"https://plus-test-1.haohao.in"'
: '"https://plus-test-1.haohao.in"'
}),
new webpack.NoEmitOnErrorsPlugin(),
new WebpackNotifierPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.ejs',
inject: 'body'
})
]
if (env === 'development') {
plugins.push(new webpack.HotModuleReplacementPlugin())
}
if (env === 'production') {
plugins.push(new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}))
}
module.exports = {
entry: [
'react-hot-loader/patch',
Path.resolve(__dirname, 'src/boot.jsx')
],
output: {
path: Path.join(__dirname, 'build'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(jsx|js)$/,
loaders: ['babel-loader'],
include: Path.join(__dirname, 'src/')
},
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{
loader: 'postcss-loader',
options: { plugins: () => [ require('autoprefixer') ] }
}
]
},
{
test: /\.scss$/,
use: [
env === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
mode: 'local',
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}
},
{
loader: 'postcss-loader',
options: { plugins: () => [ require('autoprefixer') ] }
},
{ loader: 'sass-loader' }
],
exclude: [Path.resolve(__dirname, 'src/assets/styles')]
},
{
test: /\.scss$/,
use: [
env === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{ loader: 'css-loader' },
{
loader: 'postcss-loader',
options: { plugins: () => [ require('autoprefixer') ] }
},
{ loader: 'sass-loader' }
],
include: [Path.resolve(__dirname, 'src/assets/styles')]
},
{
test: /\.(ttf|eot|png|gif|jpg|woff|woff2|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [{ loader: 'url-loader', options: { limit: 8192 } }],
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.js', '.jsx'],
modules: [Path.resolve(__dirname, 'src'), 'node_modules'],
alias: {
assets: Path.join(__dirname, 'src/assets')
}
},
devServer: {
inline: true,
hot: true,
historyApiFallback: true
},
plugins,
mode: env
}