-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
80 lines (73 loc) · 2.31 KB
/
webpack.common.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
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import webpack from 'webpack';
import dotenv from 'dotenv';
const env = dotenv.config({
path: path.join(__dirname, '.env'),
});
export { path, __filename, __dirname };
export default {
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
resolve: {
extensions: ['.ts', '.js', '.json'],
alias: {
'~': path.resolve(__dirname, './'),
'@api': path.resolve(__dirname, './src/api'),
'@components': path.resolve(__dirname, './src/components'),
'@controllers': path.resolve(__dirname, './src/controllers'),
'@pages': path.resolve(__dirname, './src/pages'),
'@utils': path.resolve(__dirname, './src/utils'),
},
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, './tsconfig.json'),
},
},
],
exclude: /(node_modules)/,
},
{
test: /\.(?:png|jpg|jpeg|svg)$/i,
type: 'asset/resource',
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {},
},
'css-loader',
'postcss-loader',
],
},
{ test: /\.hbs/, loader: 'handlebars-loader' },
],
},
plugins: [
new webpack.EnvironmentPlugin(
Object.keys(env.parsed || { API_BASE_URL: process.env?.API_BASE_URL })
),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './static/index.html',
}),
new MiniCssExtractPlugin(),
],
};