-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
73 lines (71 loc) · 1.89 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
bundle: path.resolve(__dirname, 'src/JavaScript/index.js'),
},
output: {
path: path.resolve(__dirname, 'dist'),
//name = entry{bundle:}
//[contenthash] for caching so sit load faster - btw this create the issue of multiple js files in the dist
filename: '[name][contenthash].js',
// so solve multiple files issue
clean: true,
// so svg and imgs have the same file names after imorting
assetModuleFilename: '[name][ext]',
},
// for debug
devtool: 'source-map',
// settings for npm start
devServer: {
static: {
// the same output folder
directory: path.resolve(__dirname, 'dist'),
},
//to reload on html files
watchFiles: ['src/*.html'],
hot: true,
port: 3000,
open: true, //open the browser
hot: true, //reload
compress: true,
historyApiFallback: true,
},
//loaders for sass
module: {
rules: [
{
// saying any file that ends with .scss use loaders on it
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
// babel settings
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
],
},
plugins: [
// html plugin so its create its own dist folder
new HtmlWebpackPlugin({
// tap title - going dynamically to html <%= %>
title: 'FitGym',
filename: 'index.html',
// template html file outside dist folder
//without this fill our html will be cleared everytime we build
template: 'src/template.html',
}),
],
};