-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.babel.js
171 lines (159 loc) · 4.02 KB
/
webpack.config.babel.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
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
import merge from 'merge';
import autoprefixer from 'autoprefixer';
import precss from 'precss';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import pkg from './package.json';
import clientConf from './config.client';
import { getStyleLoader } from './src/utils/webpack';
import { List } from 'immutable';
const ENV = process.env.NODE_ENV;
const PATHS = {
src: path.resolve(__dirname, './src'),
build: path.resolve(__dirname, './dist'),
modules: path.resolve(__dirname, './node_modules'),
test: path.resolve(__dirname, './test')
};
export function getPostCss() {
return function () {
return [autoprefixer, precss];
}
}
export function getCommonLoaders(ENV) {
return List([
getStyleLoader(
ENV,
{
test: /\.p?css$/,
include: [
PATHS.src,
],
loaders: [
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
'postcss-loader'
]
},
),
getStyleLoader(
ENV,
{
test: /\.css$/,
include: [
PATHS.modules,
],
loaders: [
'css-loader'
]
},
),
{
test: /\.(png|jpg|gif|ico|svg)$/,
loaders: [
'file?hash=sha512&digest=hex&name=assets/images/[hash:base58:8].[ext]',
'img?minimize&optimizationLevel=5&progressive=true'
],
include: [
PATHS.src
]
},
{
test: /font.*\.(woff|woff2|eot|ttf|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff&name=assets/fonts/[name].[ext]',
include: [
PATHS.src,
PATHS.modules
]
}
]);
}
const common = {
context: __dirname,
module: {
loaders: getCommonLoaders(PATHS, ENV).concat(
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: [
PATHS.modules,
]
}
).toJS()
},
postcss: getPostCss(),
resolve: {
modulesDirectories: ['node_modules'],
root: [
PATHS.src,
],
extensions: ['', '.js', '.jsx'],
},
resolveLoader: {
root: PATHS.modules
}
};
const plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new HtmlWebpackPlugin({
title: 'Trollo',
template: 'web/index.html',
favicon: 'web/favicon.ico',
inject: 'body'
}),
new webpack.DefinePlugin({
__DEVELOPMENT__: process.env.NODE_ENV === 'development',
__DEVTOOLS__: false,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
})
];
const envs = {
test: {
devtool: 'inline-source-map' //just do inline source maps instead of the default
},
development: {
devtool: 'cheap-module-source-map',
entry: [
'react-hot-loader/patch',
'webpack-hot-middleware/client',
'./src/client.js'
],
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: 'client.[hash].js'
},
plugins: plugins.concat([
new webpack.HotModuleReplacementPlugin(),
])
},
production: {
devtool: 'source-map',
entry: {
client: './src/client.js',
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].[chunkhash].js'
},
plugins: plugins.concat([
new ExtractTextPlugin("styles.[contenthash].css"),
new webpack.optimize.UglifyJsPlugin({
'mangle': false,
'compress': {
/* eslint-disable camelcase */
dead_code: true, // discard unreachable code
unsafe: false, // some unsafe optimizations (see below)
unused: false, // drop unused variables/functions
hoist_vars: false, // hoist variable declarations
side_effects: false, // drop side-effect-free statements
global_defs: {} // glob
/* eslint-enable camelcase */
}
}),
new webpack.NoErrorsPlugin()
])
}
}
export default merge(common, envs[ENV]);