-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.js
134 lines (129 loc) · 3.36 KB
/
webpack.dev.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* eslint-disable @typescript-eslint/no-var-requires */
const { merge } = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const fs = require('fs');
const webpack = require('webpack');
const path = require('path');
const MillionLint = require('@million/lint');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
entry: {
root: './src/index.js',
// app: './src/indexV1.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
module: true, // Bật hỗ trợ EcmaScript Module
},
experiments: {
outputModule: true, // Cho phép Webpack tạo file ESM
topLevelAwait: true, // Cho phép sử dụng dynamic import() ở cấp cao nhất
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
// {
// test: /\.css$/i,
// use: ['style-loader', 'css-loader'],
// },
{
test: /\.(sa|sc|c)ss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
esModule: false,
},
},
'postcss-loader',
],
},
{
test: /\.(jpe?g|gif|png|PNG|ico|ogg|svg)$/,
type: 'asset/resource',
generator: { filename: '[name][ext]?path=[file]&hash=[hash:10][ext][query]' },
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
type: 'asset',
},
],
},
resolve: {
extensions: ['*', '.js', '.jsx'],
},
plugins: [
new webpack.HotModuleReplacementPlugin(), // Bật hot load mudule trên webpack
new HtmlWebpackPlugin({
template: './index.html',
filename: './index.html',
inject: 'body', // Thêm file js vào thẻ body của trang
chunks: ['root'],
scriptLoading: 'module', // Load file js với type ="module"
}),
// MillionLint.webpack(),
// new HtmlWebpackPlugin({
// template: './index.html',
// filename: './v1/index.html',
// chunks: ["app"],
// }),
],
optimization: {
minimizer: [],
splitChunks: {
cacheGroups: {
default: false,
vendors: false,
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'async', // Chia nhỏ mã chỉ cho các chunk được tải động (tức là khi sử dụng dynamic import())
},
},
},
},
devServer: {
historyApiFallback: true,
// open: true,
compress: true,
hot: true,
port: 6789,
// host: 'test.getflycrm.com',
// host: '192.168.1.92', // Địa chỉ IP trong mạng LAN của bạn
// allowedHosts: 'all', // Chấp nhận tất cả các host trong mạng LAN
server: {
type: 'http',
// type: 'https',
options: {
// key: fs.readFileSync('./ssl/a.key'),
// cert: fs.readFileSync('./ssl/a.crt'),
},
},
client: { overlay: false },
},
cache: {
type: 'filesystem',
compression: 'gzip',
idleTimeout: 86400000,
buildDependencies: {
config: [__filename],
},
},
stats: {
all: false,
preset: 'errors-warnings',
builtAt: true,
colors: true,
timings: true,
errors: true,
performance: true,
},
});