-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.prod.client.config.js
More file actions
executable file
·186 lines (184 loc) · 5.06 KB
/
webpack.prod.client.config.js
File metadata and controls
executable file
·186 lines (184 loc) · 5.06 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const {resolve} = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const OfflinePlugin = require('offline-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin');
const autoprefixer = require('autoprefixer');
const ManifestPlugin = require('webpack-manifest-plugin');
const cssnext = require('postcss-cssnext');
const postcssFocus = require('postcss-focus');
const postcssReporter = require('postcss-reporter');
const browserslist = require('./browserslist');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const extractVendorCSSPlugin = new ExtractTextPlugin({
filename: 'vendor.[chunkhash].min.css',
allChunks: true
});
// const extractCSS = new ExtractTextPlugin({
// filename: '[name]-[chunkhash].min.css',
// allChunks: true
// });
const extractSCSS = new ExtractTextPlugin({
filename: '[name]-[chunkhash].min.css',
ignoreOrder: true,
allChunks: true
});
const vendorCSSLoaders = extractVendorCSSPlugin.extract({
fallback: 'style-loader',
use: ['style-loader', 'css-loader', 'sass-loader'],
});
const SCSSLoaders = extractSCSS.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]',
importLoaders: true,
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
plugins: () =>{
return [
postcssFocus(), // Add a :focus to every :hover
cssnext({ // Allow future CSS features to be used, also auto-prefixes the CSS...
browsers: ['last 2 versions', 'IE > 10'], // ...based on this browser list
}),
postcssReporter({ // Posts messages from plugins to the terminal
clearMessages: true,
}),
];
},
},
},
'sass-loader',
],
});
module.exports = {
context: resolve('src'),
entry: {
app: "./index.js",
vendor: ['react', 'react-dom', 'react-helmet', 'react-router']
},
output: {
filename: "app.[chunkhash].min.js",
publicPath: "/assets/",
path: "build/public"
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js?$/,
exclude: [/node_modules/],
use: ['babel-loader']
},
{
test: /\.s?css$/,
exclude: [/node_modules/],
use: SCSSLoaders
},
// {
// test: /\.css$/,
// use: extractCSS.extract({
// fallback: 'style-loader',
// use: 'css-loader?modules&importLoaders=1&localIndentName=[local]',
// })
// },
{
// Transform 3rd party css into an external stylesheet (vendor.[contenthash].css)
test: /\.s?css$/,
include: /node_modules/,
use: vendorCSSLoaders,
},
{
test: /\.jpg$/,
exclude: [/node_modules/],
use: 'file-loader?name=images/[path][name]-[hash].[ext]&context=src'
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {NODE_ENV: '"production"'}
}),
new ProgressBarPlugin(),
new webpack.LoaderOptionsPlugin({
options: {
context: __dirname,
postcss: [autoprefixer({browsers: browserslist})]
}
}),
new ManifestPlugin({}),
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
},
sourceMap: true
}),
extractSCSS,
extractVendorCSSPlugin,
new InlineManifestWebpackPlugin(),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor'],
filename: 'vendor-[chunkhash].min.js'
}),
new HtmlWebpackPlugin({
template: './containers/document/index.html',
favicon: './containers/document/favicon.ico'
}),
new webpack.ProvidePlugin({
// make fetch available
fetch: 'exports-loader?self.fetch!whatwg-fetch',
}),
new webpack.NamedModulesPlugin(),
new webpack.NormalModuleReplacementPlugin(
/\.\/route/,
'./routeAsync'
),
// new CopyWebpackPlugin([
// { from: 'containers/document/index.html', to: '' }
// ]),
new OfflinePlugin({
rewrites: {
'index.html': '/'
}
})
]
// new OfflinePlugin({
// externals: ['containers/document/index.html'],
// }) ]
// [
// new webpack.EnvironmentPlugin([
// "NODE_ENV"
// ]),
// new webpack.LoaderOptionsPlugin({
// options: {
// context: __dirname,
// postcss: [ autoprefixer({ browsers: browserslist }) ]
// }
// }),
// new webpack.optimize.UglifyJsPlugin({
// compressor: {
// screw_ie8: true,
// warnings: false
// }
// }),
// new ExtractTextPlugin({
// filename: '[name]-[hash].min.css',
// allChunks: true
// }),
// new ManifestPlugin({}),
// new webpack.optimize.CommonsChunkPlugin({
// name: 'vendor',
// minChunks: Infinity,
// filename: '[name]-[hash].min.js'
// })
// ]
};