-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
70 lines (69 loc) · 2 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
const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Dotenv = require('dotenv-webpack');
module.exports = {
entry: './index.ts', // Assuming your TypeScript file is named app.ts
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
// {
// test: /\.css$/,
// use: ["style-loader", "css-loader"],
// },
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader, // Extracts CSS into separate files
'css-loader', // Translates CSS into CommonJS
'postcss-loader', // Processes CSS with PostCSS
'sass-loader' // Compiles Sass to CSS
],
},
],
},
plugins: [
new Dotenv({systemvars:true}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: path.resolve(__dirname, "index.html"),
}),
new CopyWebpackPlugin({
patterns: [
{ from: './src/assets', to: 'assets' } // This copies the 'assets' folder to 'dist/assets'
],
}),
],
devServer: {
static: {
directory: path.join(__dirname, '/dist'), // This replaces contentBase
publicPath: '/', // This sets the public path for the assets
},
compress: true, // Enable gzip compression
port: 9000, // Port number for the server
hot: true, // Enable Hot Module Replacement (HMR)
open: true, // Automatically open the default browser after the server starts
devMiddleware: {
writeToDisk: true,
},
watchFiles: [
path.resolve(__dirname, './**/*.ts') // This pattern ensures all .ts files in src are watched
]
},
};