forked from phuocng/html-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
103 lines (101 loc) · 3.23 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
100
101
102
103
const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const plugins = [
new HtmlWebPackPlugin({
template: './client/index.html',
filename: './index.html',
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
ignoreOrder: false, // Enable to remove warnings about conflicting order
}),
];
module.exports = {
entry: {
'vendor-styles': [
'./vendors/[email protected]/theme.min.css',
'./vendors/[email protected]/tailwind.css',
],
// The CSS for client should come after `vendor-styles`
client: './client/index.tsx',
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[contenthash].js',
chunkFilename: '[name].[contenthash].js',
// It's very important
// All the chunk generated by webpack then will be loaded such as
// <script charset="utf-8" src="/[chunk-name].bundle.js"></script>
// The script is accessible from any page that exported by a 3rd party such as react-snap
publicPath: '/',
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development',
},
},
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('tailwindcss'),
require('cssnano'),
],
},
},
],
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
// The order of loaders are very important
// It will make the @loadable/component work
use: ['babel-loader', 'ts-loader'],
},
{
enforce: "pre",
test: /\.js$/,
loader: 'source-map-loader',
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
devtool: 'cheap-module-eavl-source-map',
devServer: {
contentBase: path.join(__dirname, 'dist'),
historyApiFallback: true,
port: 1234,
},
plugins,
// See https://webpack.js.org/guides/caching/
optimization: {
runtimeChunk: 'single',
moduleIds: 'hashed',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
// sync + async chunks
chunks: 'all',
name: 'vendors',
// import file path containing node_modules
test: /[\\/]node_modules[\\/]/,
priority: 20,
},
},
},
},
};