-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (89 loc) · 2.74 KB
/
webpack.config.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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackMerge = require('webpack-merge')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const webpack = require('webpack')
const modeConfig = env => require(`./build-utils/webpack.${env}`)(env)
const presetConfig = presets => require(`./build-utils/presets/webpack.${presets}`)(presets);
const PATHS = {
src: path.join(__dirname, './src'),
dist: path.join(__dirname, './dist')
};
module.exports = ({ mode = "production" , presets= []}) => {
return webpackMerge({
mode,
output: {
// the output bundle
filename: 'bundle.js',
// the output chunk bundle
chunkFilename : '[name].chunk.js',
// output directory
path: PATHS.dist,
publicPath: '/'
// necessary for HMR to know where to load the hot update chunks
},
optimization: {
splitChunks: {
chunks: "all",
name: false,
cacheGroups: {
vendor: {
name: 'vendors',
test: /[\\/]node_modules[\\/]/,
}
}
},
runtimeChunk: true
},
resolve: {
extensions: ['.ts', '.tsx', '.js','.jsx']
},
module: {
rules: [{
test: /\.(js|jsx)$/,
include: path.resolve(__dirname, 'src'),
use: [
'babel-loader'
],
exclude: /node_modules/
},
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.(ts|tsx)$/,
loader: ['awesome-typescript-loader', 'tslint-loader']
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
// Style loaders
// {
// test: /\.scss$/,
// use: [
// "style-loader", // creates style nodes from JS strings
// "css-loader", // translates CSS into CommonJS
// "sass-loader" // compiles Sass to CSS, using Node Sass by default
// ]
// },
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'url-loader',
options: {
limit: 8000, // Convert images < 8kb to base64 strings
name: '[name].[ext]',
publicPath: 'images/' //path for images directory
}
}, {
test: /\.(pdf|docx)$/,
loader: 'file-loader?name=documents/[name].[ext]',
}
],
},
plugins: [
new HtmlWebpackPlugin({
template:"./index.html"
}),
new webpack.ProgressPlugin(),
new CleanWebpackPlugin()
]
}, modeConfig(mode),
presets.length && presetConfig(presets))
};