-
Notifications
You must be signed in to change notification settings - Fork 543
Expand file tree
/
Copy pathwebpack.config.js
More file actions
94 lines (91 loc) · 2.81 KB
/
webpack.config.js
File metadata and controls
94 lines (91 loc) · 2.81 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
const path = require('path');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const webpack = require('webpack');
const BundleTracker = require('webpack-bundle-tracker');
module.exports = (env, argv) => {
const isDev = argv.mode === 'development';
const nodeModulesDir = path.resolve(__dirname, 'node_modules');
const localhostOutput = {
path: path.resolve('./frontend/webpack_bundles/'),
publicPath: 'http://localhost:3000/frontend/webpack_bundles/',
filename: '[name].js',
};
const productionOutput = {
path: path.resolve('./frontend/webpack_bundles/'),
publicPath: 'auto',
filename: '[name]-[chunkhash].js',
clean: true,
};
return {
mode: isDev ? 'development' : 'production',
devtool: 'source-map',
devServer: {
hot: true,
historyApiFallback: true,
host: '0.0.0.0',
port: 3000,
// Allow CORS requests from the Django dev server domain:
headers: { 'Access-Control-Allow-Origin': '*' },
},
context: __dirname,
entry: ['./frontend/js/index.tsx'],
output: isDev ? localhostOutput : productionOutput,
module: {
rules: [
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
use: {
loader: 'swc-loader',
},
},
{
test: /\.css$/,
use: [
isDev && 'style-loader',
!isDev && MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { importLoaders: 1 } },
// Tailwind v4 uses @tailwindcss/postcss (condigured in the postcss.config.mjs file)
'postcss-loader',
].filter(Boolean),
},
{
test: /\.(svg)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset',
},
{
test: /\.(woff(2)?|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset',
},
{
test: /\.(png|jpg|jpeg|gif|webp)?$/,
type: 'asset',
},
],
},
plugins: [
!isDev && new MiniCssExtractPlugin({ filename: '[name]-[chunkhash].css' }),
isDev && new ReactRefreshWebpackPlugin(),
new BundleTracker({
path: __dirname,
filename: 'webpack-stats.json',
}),
new NodePolyfillPlugin(),
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
].filter(Boolean),
resolve: {
fullySpecified: false,
modules: [nodeModulesDir, path.resolve(__dirname, 'frontend/js/')],
alias: { '@': path.resolve(__dirname, 'frontend') },
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
optimization: {
minimize: !isDev,
splitChunks: {
// include all types of chunks
chunks: 'all',
},
},
};
};