This repository was archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.common.js
More file actions
89 lines (87 loc) · 2.25 KB
/
Copy pathwebpack.common.js
File metadata and controls
89 lines (87 loc) · 2.25 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
const path = require('path');
const Dotenv = require('dotenv-webpack');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = {
plugins: [
new Dotenv(),
new CopyPlugin({
patterns: [
{
from: 'src/**/*.{jpg,png,gif,jpeg,webm,flac,mp3,mp4}',
to: path.join(__dirname, 'assets/img/[name][ext]'),
},
],
options: {
concurrency: 100,
},
}),
],
// webpack will take the files from ./src/index
entry: './src/index.tsx',
// and output it into /dist as bundle.js
output: {
path: path.join(__dirname, '/plugins'),
filename: 'abc.js',
},
// adding .ts and .tsx to resolve.extensions will help babel look for .ts and .tsx files to transpile
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
// we use babel-loader to load our jsx and tsx files
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
// css-loader to bundle all the css files into one file and style-loader to add all the styles inside the style tag of the document
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
options: {
insert: function (element) {
document.addEventListener('DOMContentLoaded', () =>
document.head.appendChild(element)
);
},
},
},
'css-loader',
],
},
{
test: /\.s(a|c)ss$/,
use: [
{
loader: 'style-loader',
options: {
insert: function (element) {
document.addEventListener('DOMContentLoaded', () =>
document.head.appendChild(element)
);
},
},
},
'css-loader',
'sass-loader',
],
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/,
exclude: /node_modules/,
include: [path.join(__dirname, './src/assets')],
type: 'asset/resource',
generator: {
outputPath: '../assets',
publicPath: '../assets',
},
sideEffects: true,
},
],
},
};