-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
118 lines (114 loc) · 2.75 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
const webpack = require('webpack')
const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const isProduction = process.argv.indexOf('-p') >= 0
module.exports = {
devtool: isProduction ? undefined : 'source-map',
// stats: 'verbose',
devServer: {
// stats: 'verbose',
host: '0.0.0.0',
port: 8080,
public: 'localhost:8080',
open: true,
historyApiFallback: {
index: '/',
},
publicPath: '/',
},
context: path.join(__dirname, './src'),
entry: './main.js',
output: {
path: path.join(__dirname, './dist'),
filename: 'bundle.[hash].js',
publicPath: './'
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
images: path.resolve(__dirname, 'src/assets/images/'),
}
},
module: {
rules: [{
test: /\.jsx?$/,
loader: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.s?css$/,
oneOf: [{
resourceQuery: /global/, // foo.css?global
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader'
},
{
loader: 'sass-loader'
}
]
})
},
{
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
modules: true,
sourceMap: true,
importLoaders: 2,
localIdentName: '[local]__[hash:base64:5]'
}
},
{
loader: 'sass-loader'
}
]
})
}
]
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}]
},
{
test: /\.(png|jpe?g|gif|svg)$/,
use: [{
loader: 'url-loader?limit=10000',
}]
}
]
},
plugins: [
new ExtractTextPlugin('bundle.[hash].css'),
new HtmlWebpackPlugin({
template: './assets/index.html'
}),
new webpack.NormalModuleReplacementPlugin(/(.*)_BUILD_TARGET_(\.*)/, function (resource) {
resource.request = resource.request.replace(/_BUILD_TARGET_/, isProduction ? 'production' : 'development');
}),
new CopyWebpackPlugin([
//{ from: './assets/images', to: './images' },
//{ from: './assets/fonts', to: './fonts' }
])
]
}
if (isProduction) {
module.exports.plugins.push(
new UglifyJsPlugin({
sourceMap: true
})
)
}