React - Django webpack config with dynamic 'output'
Have:
I have a Django app. It has react for front-end. I have 2 django apps. movies_list
and series_list
. I have all my .jsx files inside baseapplication/movies_list/interfaces/
and baseapplication/series_list/interfaces/
. The entry point of 2 apps is given ...../index
as given in entry
object of web-pack.config.js
.
Need:
I need to put my compiled .js
files inside baseapplication/movies_list/static/movies_list
and baseapplication/series_list/static/series_list
. So I need to find each entry in entry
and get the abs path and construct my output
path dynamically for the future apps. This will help my python manage.py collectstatic
to get static files from each directory.
How to configure the output
to make it dynamic?
module.exports = {
//The base directory (absolute path) for resolving the entry option
context: __dirname,
entry: {
movies: '../movies_list/interfaces/index',
series: '../series_list/interfaces/index',
},
output: {
// I need help here.
path: path.join('<', "static"),
//path: path.resolve('../[entry]/static/react_bundles/'),
filename: "[name].js",
},
}
Answer
You can set entry points to a full path of the resulting file. Something like this should work:
module.exports = {
context: __dirname,
entry: {
'baseapplication/movies_list/static/movies_list/index': '../movies_list/interfaces/index',
'baseapplication/series_list/static/series_list/index': '../series_list/interfaces/index',
},
output: {
path: './',
filename: "[name].js",
},
}