-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
129 lines (125 loc) · 4.17 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
119
120
121
122
123
124
125
126
127
128
129
import webpack, { ProvidePlugin } from 'webpack'
import path from 'path'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import ChunkManifestPlugin from '@codemotion/chunk-manifest-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import ImageminWebpackPlugin from 'imagemin-webpack-plugin'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import CleanWebpackPlugin from 'clean-webpack-plugin'
import GitRevisionPlugin from 'git-revision-webpack-plugin'
import mozJPEG from 'imagemin-mozjpeg'
import glob from 'glob'
export default {
entry: {
bundle: "./src/index.js",
vendor: ['react','redux','redux-saga','babel-polyfill']
},
output: {
path: path.resolve(__dirname,'build'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
publicPath: '/'
},
resolve: {
extensions: ['*','.js','.jsx']
},
module: {
rules: [
{
test: /\.jsx?$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
use: {
loader: 'css-loader',
options: {minimize: true}
},
fallback: 'style-loader'
}),
exclude: /node_modules/
},
{
test: /\.(jpe?g|png|gif)/,
use: {
loader:'file-loader',
options:{
emitFile: false,
name: '[path][name].[ext]'
}},
exclude: /node_modules/
},
{
test: /\.html/,
use:['html-loader','posthtml-loader']
}
]
},
target: 'web',
plugins: [
new webpack.BannerPlugin({
banner: `GIT ${new GitRevisionPlugin().branch()} REV. ${new GitRevisionPlugin().version()}`
}),
new CleanWebpackPlugin('build'),
new ExtractTextPlugin({
filename: 'styles.css',
allChunks: true
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
}),
new ProvidePlugin({
React: 'react'
}),
new webpack.NamedChunksPlugin((chunk) => {
if(chunk.name)
return chunk.name
return chunk.mapModules(module => {
if(/html-webpack-plugin/.test(module.userRequest)) return 'html-webpack-plugin'
return path.relative(module.context,module.userRequest).replace('.js','')
}).reduce((acc,item) => acc.length <= 3 ? (() =>{acc.push(item); return acc})() : acc,[]).join('-')
}),
new webpack.NamedModulesPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: ['vendor'],
minChunks: Infinity
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['manifest'],
minChunks: Infinity,
filename: '[name].js'
}),
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: '[name].[chunkhash].js'
}),
new HtmlWebpackPlugin({
template: './src/template.html',
title: 'Webpack',
filename: 'index_no.html',
injectManifest: false
}),
new ChunkManifestPlugin({
filename: 'manifest.json',
manifestVariable: 'webpackManifest',
inlineManifest: true
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new CopyWebpackPlugin([
...glob.sync('images/*.png')
.map(source => ({from: source, to:'images' })),
...glob.sync('images/*.jpg')
.map(source => ({from: source, to:'images'}))]
),
new ImageminWebpackPlugin({
jpegtran: null,
plugins: [mozJPEG({
quality: 100,
progressive: true
})],
test: /\.(png|jpe?g)/
})
]
}