-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
110 lines (102 loc) · 2.78 KB
/
webpack.config.js
File metadata and controls
110 lines (102 loc) · 2.78 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var isProduction = process.argv.indexOf('-p') != -1;
var path = require('path');
var plugins = [];
var entryPoints = [
'react-hot-loader/patch',
'./app/devIndex.tsx'
];
if (isProduction) {
// Adding Production environment specific features.
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
sourceMap: true
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
})
);
} else {
// Adding Development environment specific features.
entryPoints.push(
'webpack/hot/only-dev-server' // Used to enable hot reloading in webpack.
);
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development')
}
})
}
plugins.push(
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.ejs'
}),
new ExtractTextPlugin({
filename: 'style.css',
allChunks: true
})
);
var config = {
entry: entryPoints,
output: {
path: path.resolve(__dirname, 'dist'),
filename: isProduction ? 'bundle.[hash].min.js' : 'bundle.js',
publicPath: '/'
},
devtool: isProduction ? false : 'source-map',
devServer: {
historyApiFallback: true
},
resolve: {
modules: [
path.resolve(__dirname, './app'),
'node_modules'
],
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.css', '.json']
},
module: {
rules: [
{
test: /\.tsx?$/,
enforce: "pre",
loader: 'tslint-loader',
exclude: [/node_modules/,/tests/]
},
{
test: /\.tsx?$/,
exclude: [/node_modules/,/tests/],
use: [
'react-hot-loader/webpack',
'ts-loader'
]
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
},
{
test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
use: [
'url-loader?limit=10&mimetype=image/(jpg|jpeg|gif|png)&name=assets/images/[name].[ext]'
]
}
]
},
plugins: plugins
};
module.exports = config;