-
Notifications
You must be signed in to change notification settings - Fork 19
/
webpack.config.js
207 lines (189 loc) · 6.05 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
'use strict';
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const Webpack_isomorphic_tools_plugin = require('webpack-isomorphic-tools/plugin');
const merge = require('merge');
var autoprefixer = require('autoprefixer');
var precss = require('precss');
const ENV = process.env.NODE_ENV;
const PATHS = {
src: path.resolve('./src'),
build: path.resolve('./dist'),
modules: path.resolve('./node_modules'),
test: path.resolve('./test')
};
let webpack_isomorphic_tools_plugin;
webpack_isomorphic_tools_plugin = new Webpack_isomorphic_tools_plugin(require('./webpack-isomorphic'));
if (ENV === 'DEVELOPMENT') {
webpack_isomorphic_tools_plugin = webpack_isomorphic_tools_plugin.development();
}
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const pkg = require('./package.json');
function getStyleLoader(env, ret, loaders)
{
let loader;
if (env !== 'prod') {
loaders.unshift('style-loader');
ret.loaders = loaders;
} else {
ret.loader = ExtractTextPlugin.extract(
'style-loader',
loaders
);
}
return ret;
}
const common = {
context: __dirname,
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: [
PATHS.modules,
]
},
getStyleLoader(
ENV,
{
test: /\.p?css$/,
include: [
PATHS.src,
]
},
[
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
'postcss-loader'
]
),
getStyleLoader(
ENV,
{
test: /\.css$/,
include: [
PATHS.modules,
]
},
[
'css-loader'
]
),
{
test: webpack_isomorphic_tools_plugin.regular_expression('images'),
loaders: [
'file?hash=sha512&digest=hex&name=assets/images/[hash:base58:8].[ext]',
'img?minimize&optimizationLevel=5&progressive=true'
],
include: [
PATHS.src
]
},
{
test: /\.(woff|woff2|eot|ttf)(\?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
]
},
{
test: /\.(svg)(\?v=[0-9]\.[0-9]\.[0-9])$/,
loader: 'file-loader?name=assets/fonts/[name].[ext]',
include: [
PATHS.src,
PATHS.modules
]
}
]
},
postcss: function () {
return [autoprefixer, precss];
},
resolve: {
modulesDirectories: ['node_modules', 'src'],
root: [
PATHS.src,
],
extensions: ['', '.js', '.jsx']
}
};
const envs = {
test: {
devtool: 'inline-source-map' //just do inline source maps instead of the default
},
development: {
devtool: 'cheap-module-source-map',
entry: [
'webpack-hot-middleware/client',
'./src/client.js'
],
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: 'client.[hash].js'
},
plugins: [
webpack_isomorphic_tools_plugin,
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
title: 'JavaScript SchamaScript',
template: 'web/index.html',
favicon: 'web/favicon.ico',
inject: 'body'
}),
new webpack.DefinePlugin({
__DEVELOPMENT__: process.env.NODE_ENV === 'development',
__DEVTOOLS__: false
}),
]
},
prod: {
devtool: 'source-map',
entry: {
client: './src/client.js',
vendor: Object.keys(pkg.dependencies)
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].[chunkhash].js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin(
'vendor',
'[name].[chunkhash].js'
),
webpack_isomorphic_tools_plugin,
new webpack.optimize.OccurenceOrderPlugin(),
new ExtractTextPlugin("styles.[contenthash].css"),
new HtmlWebpackPlugin({
title: 'Pekkis Goes To Movies',
template: 'web/index.html',
favicon: 'web/favicon.ico',
inject: 'body',
}),
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(),
new webpack.DefinePlugin({
__DEVELOPMENT__: process.env.NODE_ENV === 'development',
__DEVTOOLS__: false
}),
]
}
}
module.exports = merge(common, envs[ENV]);