-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
99 lines (94 loc) · 2.52 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
// import basic libraries
import webpack from 'webpack';
import path from 'path';
// import webpack plugins
import WebpackCleanupPlugin from 'webpack-cleanup-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
// define extraction plugin for styles
const extractStylePlugin = new ExtractTextPlugin({
filename: "styles.[hash].css"
});
// define directory paths
const BUILD_DIR = path.resolve(__dirname, 'build');
const APP_DIR = path.resolve(__dirname, 'src');
const config = {
mode: 'production',
entry: {
'app': APP_DIR + '/index.ts'
},
output: {
path: BUILD_DIR,
filename: '[name].[hash].js'
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.(js)$/,
include: APP_DIR,
loader: 'babel-loader'
},
{
test: /\.(ts)$/,
include: APP_DIR,
loader: 'awesome-typescript-loader'
},
{
test: /\.scss$/,
use: extractStylePlugin.extract({
use: [{
loader: 'css-loader'
}, {
loader: 'sass-loader'
}],
fallback: 'style-loader'
})
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name: 'images/[name].[ext]'
}
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]'
}
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
}
}
}
},
plugins: [
new HtmlWebpackPlugin({
title: 'Traze',
filename: 'index.html',
template: APP_DIR + '/html/index.ejs',
chunks: ['app', 'vendor']
}),
new WebpackCleanupPlugin(),
extractStylePlugin
],
devServer: {
contentBase: [BUILD_DIR],
compress: true,
port: 9009,
watchContentBase: true
}
};
export default config;