I have a large django project, with multiple apps, and each application has its own static directory like this /[appname]/static/[appname]/[css, js, or img directory].
I have multiple entrypoints because of this (and because I want to use code splitting), so my webpack config file with two apps looks like this:
const path = require('path')
module.exports = {
entry: {
core: './core/static/core/js/base.js',
info: './info/static/info/js/base.js',
},
output: {
filename: '[name]/bundle.js',
path: path.resolve(__dirname, 'core', 'static', 'dist'),
},
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
};
My problem is that instead of sending all the bundled files to the "dist" sub-directory inside my "core" app's static directory I want the output directory (path) to be dynamically generated like this [appname]/static/[appname]/dist. Is there a way to do this?
One solution I thought of was to just set the output filename to be '[name]/static/[name]/dist/'. This worked, however, because the output directory wasnt specified any images loaded from the css files were placed in the root directory of my project, not the "dist" sub-directory.