-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
87 lines (79 loc) · 2.9 KB
/
webpack.config.js
File metadata and controls
87 lines (79 loc) · 2.9 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
'use strict';
const path = require('path');
const HtmlwebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const merge = require('webpack-merge');
const pkg = require('./package.json');
const Clean = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const TARGET = process.env.npm_lifecycle_event;
const ROOT_PATH = path.resolve(__dirname);
const APP_PATH = path.resolve(ROOT_PATH, 'src');
const BUILD_PATH = path.resolve(ROOT_PATH, 'build');
process.env.BABEL_ENV = TARGET;
const common = {
resolve: {
extensions: ['', '.js', '.jsx'],
},
};
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
entry: APP_PATH,
output: {
path: BUILD_PATH,
filename: 'bundle.js',
},
devtool: 'eval-source-map',
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
// parse host and port from env so this is easy to customize
host: process.env.HOST,
port: process.env.PORT,
},
module: {
preLoaders: [
{test: /\.jsx?$/, loader: 'eslint-loader', include: APP_PATH },
],
loaders: [
{ test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/, loader: 'url-loader?limit=30000&name=[name]-[hash].[ext]' },
{ test: /\.css$/, loaders: ['style', 'css'], include: APP_PATH },
{ test: /\.jsx?$/, loaders: ['react-hot', 'babel'], include: APP_PATH },
],
},
plugins: [
new HtmlwebpackPlugin({ title: 'Ginder - Techdencias', template: path.resolve(ROOT_PATH, 'index.ejs'), inject: 'body' }),
new webpack.HotModuleReplacementPlugin(),
],
});
}
if ( TARGET === 'build' || TARGET === 'stats' || (/^deploy.*$/.test(TARGET)) ) {
module.exports = merge(common, {
devtool: 'source-map',
entry: {
app: APP_PATH,
vendor: Object.keys(pkg.dependencies),
},
output: {
path: BUILD_PATH,
filename: '[name].[chunkhash].js?',
},
module: {
loaders: [
{ test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/, loader: 'url-loader?limit=30000&name=[name]-[hash].[ext]' },
{ test: /\.css$/, loader: ExtractTextPlugin.extract('style', 'css'), include: APP_PATH },
{ test: /\.jsx?$/, loaders: ['babel'], include: APP_PATH },
],
},
plugins: [
new Clean(['build']), // clean build previous builds
new HtmlwebpackPlugin({ title: 'Ginder - Techdencias', template: path.resolve(ROOT_PATH, 'index.ejs'), inject: 'body' }),
new ExtractTextPlugin('styles.[chunkhash].css'), // separate styles of app.js
new webpack.optimize.CommonsChunkPlugin( 'vendor', '[name].[chunkhash].js' ), // separate vendor and app
new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('production') } }), // more minification
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), // minification
],
});
}