-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
101 lines (99 loc) · 2.74 KB
/
webpack.common.js
File metadata and controls
101 lines (99 loc) · 2.74 KB
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
// This is required to automatically add the html file to the bundle
const HtmlWebpackPlugin = require("html-webpack-plugin");
// This is required to keep output styles in css files not in a js file
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// To create a base path for the project
const path = require("path");
const basePath = __dirname;
module.exports = {
context: path.join(basePath, "src"),
resolve: {
extensions: [".js", ".ts", ".tsx"],
alias: {
router: path.resolve(__dirname, "./src/router/"),
images: path.resolve(__dirname, "./src/assets/img"),
},
},
entry: {
// To define the files used in dev mode
app: ["./index.tsx"],
appStyles: ["./style.scss"],
},
output: {
// To define the files we want to have after bundling
filename: "./js/[name].[chunkhash].js",
},
module: {
rules: [
{
// Loader for handling js files
test: /\.tsx?$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[name]__[local]__[hash:base64:5]",
exportLocalsConvention: "camelCase",
},
},
},
{
loader: "sass-loader",
options: {
implementation: require("sass"),
},
},
],
},
{
//Loader for handling css files
test: /\.css$/,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
// Loader for handling images
test: /\.(png|jpg)$/,
exclude: /node_modules/,
use: {
loader: "url-loader",
options: {
limit: 5000,
name: "./img/[hash].[name].[ext]",
esModule: false,
},
},
},
{
// Loader for processing output references images in the html
test: /\.html$/,
loader: "html-loader",
},
],
},
plugins: [
//Generate index.html in /dist => https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: "index.html", //Name of file in ./dist/
template: "index.html", //Name of template in ./src
// hash: true, //No necessary if we use chunkhash in the output file
}),
//Generate styles in css files in /dist
new MiniCssExtractPlugin({
filename: "./css/[name].[chunkhash].css",
chunkFilename: "[id].css",
}),
],
// To configure the default local server
// devServer: {
// port: 8081,
// },
};