-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
125 lines (119 loc) · 2.85 KB
/
webpack.config.ts
File metadata and controls
125 lines (119 loc) · 2.85 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import * as webpack from 'webpack';
import * as path from 'path';
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
chunksSortMode: 'dependency',
template: path.join(__dirname, '/src/index.html'),
filename: 'index.html',
favicon: path.join(__dirname, '/src/static/react-icon-small.png'),
inject: 'body'
});
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build'),
dist: path.join(__dirname, 'dist'),
components: path.join(__dirname, './src/components'),
containers: path.join(__dirname, './src/containers'),
styles: path.join(__dirname, './src/styles')
};
const isProduction = process.env.npm_lifecycle_event === 'build';
const baseConfig = {
entry: {
main: './src/index.tsx',
vendor: ['react', 'react-dom', 'react-router']
},
module: {
rules: [
{
test: /\.(t|j)sx?$/,
use: ['babel-loader', 'awesome-typescript-loader'],
exclude: /node_modules/
},
{ test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
{
test: /\.(png|svg|jpg|gif)$/,
use: 'file-loader'
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
components: PATHS.components,
containers: PATHS.containers,
styles: PATHS.styles
}
}
};
const developmentConfig = {
entry: {
main: ['react-hot-loader/patch', './src/index.tsx'],
vendor: ['react', 'react-dom', 'react-router']
},
output: {
path: PATHS.dist,
publicPath: '/',
filename: '[hash].[name].js'
},
devtool: 'eval-source-map',
devServer: {
contentBase: PATHS.dist,
historyApiFallback: true,
hot: true,
inline: true,
quiet: false
},
plugins: [
HtmlWebpackPluginConfig,
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common'
}),
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
generateStatsFile: true,
statsFilename: 'stats.json'
})
]
};
const productionConfig = {
output: {
path: PATHS.dist,
filename: '[chunkhash].[name].js'
},
devtool: 'source-map',
plugins: [
new CleanWebpackPlugin(['dist']),
HtmlWebpackPluginConfig,
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common'
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
})
]
};
export default (<any>Object).assign(
{},
baseConfig,
isProduction === true ? productionConfig : developmentConfig
);