forked from scalable-react/scalable-react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.prod.js
182 lines (179 loc) · 4.66 KB
/
webpack.config.prod.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
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
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const OfflinePlugin = require('offline-plugin');
const autoprefixer = require('autoprefixer');
const precss = require('precss');
const ManifestPlugin = require('webpack-manifest-plugin');
const ROOT_PATH = path.resolve(__dirname);
const PORT = process.env.PORT || 1337;
const HOST = '0.0.0.0'; // Set to localhost if need be.
module.exports = {
devtool: 'source-map',
entry: {
main: [
path.resolve(ROOT_PATH, 'app/src/index')
],
vendor: [
'react',
'react-dom',
'grommet',
'react-redux',
'react-router',
'react-router-redux',
'redux',
'redux-form',
'reselect',
'styled-components',
'redux-auth-wrapper',
'redux-thunk',
'functional-components'
],
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.md$/,
use: ['html-loader','markdown-loader']
},
{
test: /\.svg$/,
use: ['babel-loader','svg-react-loader']
},
{
test: /\.json$/,
use: 'json-loader'
},
{
test: /\.(sass|sss|css)$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: function() {
return [
require('precess'),
require('autoprefixer'),
autoprefixer({browsers: []})
]
}
}
},
'sass-loader'
]
},
{
test: /\.module\.scss$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
fallback: 'style-loader',
modules: 1,
importLoaders: 1,
localIdentName: '[path]___[name]__[local]___[hash:base64:5]'
},
},
'resolve-url-loader',
'postcss-loader',
'sass-loader'
]
})
},
{
test: /\.scss$/,
exclude: [/\.module\.scss$/],
use: ExtractTextPlugin.extract({
use: [
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
sourceMap: true,
includePaths: [
path.join(ROOT_PATH, 'node_modules')
],
outputStyle: 'compressed'
}
}
]
})
},
{
test: /\.woff(2)?(\?v=[0-9].[0-9].[0-9])?$/,
loader: "url-loader?mimetype=application/font-woff"
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9].[0-9].[0-9])?$/,
loader: "file-loader?name=[name].[ext]"
},
{
test: /\.(jpg|png)$/,
loader: 'file-loader?name=[path][name].[hash].[ext]'
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.scss', '.css'],
alias: {
components: path.resolve(ROOT_PATH, 'app/src/components'),
containers: path.resolve(ROOT_PATH, 'app/src/containers'),
pages: path.resolve(ROOT_PATH, 'app/src/pages'),
utils: path.resolve(ROOT_PATH, 'app/src/utils')
},
modules: [
path.join(__dirname, 'src'), 'node_modules'
],
},
output: {
path: path.resolve(ROOT_PATH, 'server/public'),
publicPath: '/',
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].chunk.js',
},
stats: {
chunks: true,
},
plugins: [
new ManifestPlugin({
fileName: 'manifest.json',
basePath: '/'
}),
new ExtractTextPlugin('[name].[contenthash].css'),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
children: true,
minChunks: 2,
async: true,
}),
new OfflinePlugin({
relativePaths: false,
publicPath: '/',
caches: {
main: [':rest:'],
// All chunks marked as `additional`, loaded after main section
// and do not prevent SW to install. Change to `optional` if
// do not want them to be preloaded at all (cached only when first loaded)
additional: ['*.chunk.js'],
},
safeToUseOptionalCaches: true,
AppCache: false,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
}),
new webpack.optimize.OccurrenceOrderPlugin(true),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false
}),
]
};