This repository was archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.base.js
More file actions
145 lines (133 loc) · 4.35 KB
/
Copy pathwebpack.config.base.js
File metadata and controls
145 lines (133 loc) · 4.35 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
const webpack = require('webpack')
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const routeLoader = require('./web_loaders/routes-loader')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const purify = require('purify-css')
const DirectoryNameAsMain = require('webpack-directory-name-as-main')
const AssetsPlugin = require('assets-webpack-plugin')
const REACT_REFORM_SRC = path.join(__dirname, '..', 'src')
module.exports = function(env) {
const isDev = env === 'dev'
const isProdServer = env === 'prod-server' // render html
const isProdClient = env === 'prod-client' // bundle js and css
const isProd = isProdClient || isProdServer
process.env.NODE_ENV = isProd ? 'production' : 'development'
const envVars = Object.assign({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
return {
bail: isProd,
contentBase: path.join(__dirname, 'src'),
entry: Object.assign(isProdServer ? {
'generate-html': './src/generate-html.js'
} : {
'main': [
...(isDev ? [require.resolve('react-dev-utils/webpackHotDevClient')] : []),
'./src/client.js'
]
}),
output: Object.assign({
filename: `[name]-[${isDev ? 'hash' : 'chunkhash'}].js`,
chunkFilename: '[id]-[chunkhash].chunk.js',
path: isProd ? '../docs' : '/',
publicPath: '/',
libraryTarget: 'umd', // required by StaticSiteGeneratorPlugin,
hashDigestLength: 5
}, isDev ? {
pathinfo: true
} : {}),
devtool: isProdServer ? false : isProdClient ? 'source-map' : 'eval',
module: {
loaders: [
...(isProdServer ? [
{
test: /\.html$/,
loader: 'html',
query: {
attrs: ['img:src', 'link:href'],
conservativeCollapse: false
}
}
] : []),
{
test: /\.js?$/,
loader: path.join(__dirname, 'node_modules', 'babel-loader'),
exclude: /node_modules|comps\/recipes/,
query: {
cacheDirectory: true
}
},
{
test: /\.css$/,
loader: isProd ? ExtractTextPlugin.extract('style', 'css?sourceMap') : 'style!css'
},
{
test: /\.svg\?inline$/,
loader: 'svg-inline'
},
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)$/,
exclude: /\/favicon.ico$/,
loader: 'file',
query: {
name: 'static/media/[name].[hash:5].[ext]'
}
},
{
test: /\/favicon.ico$/,
loader: 'file',
query: {
name: 'favicon.ico?[hash:8]'
}
},
]
},
resolve: {
modulesDirectories: ['./src', 'node_modules'],
alias: {
'react-reform': REACT_REFORM_SRC,
'react': path.join(__dirname, 'node_modules', 'react')
}
},
plugins: [
new webpack.ResolverPlugin([
new DirectoryNameAsMain()
]),
new webpack.ContextReplacementPlugin(/moment[\\\/]lang$/, /^\.\/(en-gb)$/),
new webpack.DefinePlugin(Object.assign(envVars, {
__DEV__: isDev,
__SERVERRENDER__: isProdServer,
'define.amd': 'false' // because of bootstrap-daterangepicker
})),
...(isProd ? [
new ExtractTextPlugin('[name]-[contenthash].css')
] : []),
...(isProdServer ? [
new StaticSiteGeneratorPlugin(
'generate-html',
routeLoader.getRoutes('src/pages/Home.js'),
{
purify: purify, clientAssets: require('../docs/webpack-assets.json'),
pathLib: path, fs: require('fs'), pathToDocs: path.join(__dirname, '..', 'docs')
},
{}
),
] : []),
...(isProdClient ? [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new AssetsPlugin({path: path.join(__dirname, '..', 'docs')}),
new webpack.optimize.UglifyJsPlugin({
compress: {screw_ie8: true, warnings: false},
mangle: {screw_ie8: true},
output: {comments: false, screw_ie8: true}
}),
] : []),
...(isDev ? [
new HtmlWebpackPlugin({inject: true, template: './src/index.html'})
] : [])
]
}
}