-
Notifications
You must be signed in to change notification settings - Fork 18
/
webpack.config.js
executable file
·125 lines (118 loc) · 4.15 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
'use strict';
var webpack = require('webpack'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
path = require('path'),
staticResourcePath = path.join(__dirname, 'static'),
srcPath = path.join(__dirname, 'src'),
nodeModulesPath = path.join(__dirname, 'node_modules');
var isProduction = function () {
return process.env.NODE_ENV === 'production';
}
var modulePath = { // production
React : path.join(nodeModulesPath, 'react/dist/react.min.js'),
React_addons : path.join(nodeModulesPath, 'react/dist/react-with-addons.min.js'),
React_Router : path.join(nodeModulesPath, 'react-router/umd/ReactRouter.min.js')
},
moduleAlias = isProduction() ?
{ // production
'react/addons' : [modulePath.React_addons],
'react' : [modulePath.React],
'react-router' : [modulePath.React_Router],
// static resources
'static' : staticResourcePath
} :
{
// static resources
'static' : staticResourcePath
},
noParse = isProduction() ?
[
modulePath.React,
modulePath.React_addons,
modulePath.React_Router
] : [];
// Project config
var page = {
settings: {
AjaxDomain: 'mobile.' + 'tonghs.me'//'angelcrunch.com'// tonghs.me
}
};
var defineStatePlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse(process.env.NODE_ENV === 'production' ? 'false' : 'true')),
__AjaxDomain: JSON.stringify(page.settings.AjaxDomain)
});
module.exports = {
target: 'web',
cache: true,
entry: {
module : path.join(srcPath, 'module.js'),
common : ['jquery', 'react', 'react-router', 'alt', 'react-mixin', 'utils/titleHelper']
},
resolve: {
root: srcPath,
extensions: ['', '.js'],
modulesDirectories: ['node_modules', 'src'],
alias: moduleAlias
},
output: {
path: path.join(__dirname, 'tmp'),
publicPath: '/',
filename: '[name].[hash].js',
library: ['Example', '[name]'],
pathInfo: true
},
module: {
loaders: [
{ test: /\.js?$/, exclude: /node_modules/, loader: 'babel?cacheDirectory' },
{
test: /.*\/(react-mixin)\/.*\.js$/,
exclude: /.spec.js/,
loader: 'uglify'
},
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' },
{ test: /\.css$/, loader: 'style!css' },
{
test: /.*\.(png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}'
]
},
{
test: /\.(jpg)$/,
loader: 'url?limit=25000'
},
{
test: /\.(woff|ttf)$/,
loader: 'url?limit=100000'
}
],
noParse: noParse
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('common', 'common.js'),
new HtmlWebpackPlugin({
inject: true,
excludeChunks: ['test'],
template: 'src/index.html'
}),
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$super', '$', 'exports', 'require']
},
compress: {
warnings: false
}
}),
new webpack.NoErrorsPlugin(),
defineStatePlugin
],
debug: isProduction() ? false : true,
devtool: isProduction() ? ''
: 'eval-cheap-module-source-map',
devServer: {
port: 9090,
contentBase: './tmp',
historyApiFallback: true
}
};