This repository has been archived by the owner on Feb 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
158 lines (141 loc) · 4.03 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
import path from 'path';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import SpriteWebpack from 'sprite-webpack-plugin';
import pkg from './package.json';
const resolve = path.resolve;
const isDevelopment = pkg.config.env.dev === (process.env.NODE_ENV || pkg.config.env.dev);
console.log(
'Is development?', isDevelopment,
'\nSource: ', resolve(__dirname, pkg.config.path.src),
'\nBuild:', resolve(__dirname, pkg.config.path.build)
);
let config = {
cache: !isDevelopment,
debug: isDevelopment,
devtool: 'source-map',
context: resolve(__dirname, pkg.config.path.src),
entry: {
'./scripts/base.js': pkg.config.base,
'./styles/base.css': pkg.config.style,
},
output: {
path: resolve(__dirname, pkg.config.path.build),
filename: '[name]',
publicPath: '/'
},
resolve: {
extensions: ['', '.js', '.jsx', '.styl'],
},
module: {
preLoaders: [
{
test: /(\.js|\.jsx)$/,
exclude: /(node_modules|build)/,
loader: 'eslint-loader',
include: path.join(__dirname, pkg.config.path.src, 'scripts')
}
],
loaders: [
{
test: /(\.js|\.jsx)$/,
exclude: /(node_modules|build)/,
loader: 'babel',
include: path.join(__dirname, pkg.config.path.src, 'scripts'),
query: {
presets: ['react', 'es2015', 'stage-0']
}
},
{
test: /\.styl$/,
loader: ExtractTextPlugin.extract(
'css?sourceMap' + (!isDevelopment ? '&minimize' : '') + '!stylus?sourceMap'
)
},
{
test: /\.eot$|\.woff$|\.woff2$|\.ttf$|\.wav$|\.mp3$/,
loader: 'file?name=[path][hash].[ext]'
},
{
test: /\.jpe?g$|\.gif$|\.png$|\.svg$/i,
loaders: [
'file?name=[path][hash].[ext]'
].concat(
isDevelopment
? [] : [
'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}'
]
)
}
]
},
plugins: [
new HtmlWebpackPlugin({
title: pkg.name,
inject: false,
minify: {
collapseInlineTagWhitespace: true,
collapseWhitespace: !isDevelopment,
removeAttributeQuotes: true,
removeComments: !isDevelopment,
},
cache: !isDevelopment,
template: resolve(__dirname, pkg.config.path.src, pkg.config.path.views, pkg.config.html)
}),
new ExtractTextPlugin('[name]', {allChunks: true}),
new webpack.EnvironmentPlugin(['NODE_ENV']),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new SpriteWebpack({
'source': resolve(__dirname, pkg.config.path.src, 'assets/images/spriting/'),
'imgPath': resolve(__dirname, pkg.config.path.src, 'assets/images/'),
'cssPath': resolve(__dirname, pkg.config.path.src, 'styles/includes/sprites/'),
'bundleMode': 'multiple',
'prefix': 'sprt',
})
].concat(
isDevelopment
? [] : [
new webpack.optimize.UglifyJsPlugin({
include: /(\.js|\.jsx)$/,
exclude: /(node_modules|build)/,
sourceMap: true,
output: {
comments: true
},
compressor: {
screw_ie8: true,
keep_fnames: true,
warnings: false
},
mangle: {
screw_ie8: true,
keep_fnames: true
}
})
]
),
eslint: {
configFile: resolve(__dirname, '.eslintrc')
}
};
/*WebpackDevServer*/
if (isDevelopment) {
new WebpackDevServer(webpack(config), {
contentBase: resolve(__dirname, pkg.config.path.build),
hot: true,
debug: true
}).listen(pkg.config.port, pkg.config.host, function (err, result) {
if (err) {
console.log(err);
}
});
console.log(
'Running at:',
`${pkg.config.protocol}${pkg.config.host}:${pkg.config.port}`
);
}
export default config;