Hi,
I want to use aurelia js with django, so how can i include aurelia in django project
I think the easiest is to develop them independently, which means you run Aurelia development tool (typically Aurelia-CLI or Webpack) in watch mode, and rebuild distribution files on changes to client folder of your Django project. Then you can server it like a normal website. I donât know it enough to tell you more than this, but I can help around the first part.
@bigopon can you eloberate it, actually I am new to it and not getting initial setup so that (for aurelia build process).
Set the build output of the Aurelia program to the client side location of Django. I believe you do this in
aurelia.json change the line
âoutputâ: âwwwroot/distâ to -> client side place django is looking relative to the aurelia project
you might need some ~/ or âŠ/âŠ/ etc.
Hi @brandonseydel,
I am using Aurelia CLI/webpack and I am not using aurelia.json, so in this case how can I use it in django?
It does use it though. It imports the aurelia.json and references it to a variable.
From webpack.config
const project = require('./aurelia_project/aurelia.json');
const outDir = path.resolve(__dirname, project.platform.output);
Check out django-webpack-loader. This works great with Aurelia, with minimal setup.
In your django settings:
Add âwebpack-loaderâ to INSTALLED_APPS
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'dist/',
'STATS_FILE': os.path.join(BASE_DIR, 'path_to_aurelia_goes_here/webpack-stats.json'),
},
}
In your webpack.config.js you need something like this:
output: {
path: outDir,
publicPath: production ? â/static/â : âhttp://localhost:9001/â,
filename: production ? â[name].[chunkhash].bundle.jsâ : â[name].[hash].bundle.jsâ,
sourceMapFilename: production ? â[name].[chunkhash].bundle.mapâ : â[name].[hash].bundle.mapâ,
chunkFilename: production ? â[name].[chunkhash].chunk.jsâ : â[name].[hash].chunk.jsâ
},
devServer: {
contentBase: outDir,
// serve main.html for all 404 (required for push-state)
historyApiFallback: true,
headers: {
âAccess-Control-Allow-Originâ: â*â,
âAccess-Control-Allow-Methodsâ: âGET, POST, PUT, DELETE, PATCH, OPTIONSâ,
âAccess-Control-Allow-Headersâ: âX-Requested-With, content-type, Authorizationâ
}
},
in the Django template which should house your application:
{% load render_bundle from webpack_loader %}
{% if debug %}
{% render_bundle âvendorâ config=âDEFAULTâ %}
{% render_bundle âappâ config=âDEFAULTâ %}
{% else %}
{% render_bundle âcommonâ config=âDEFAULTâ %}
{% render_bundle âappâ config=âDEFAULTâ %}
{% render_bundle âvendorâ config=âDEFAULTâ %}
{% endif %}
To use this do au run --watch in your aurelia project and run the django development web server.
I think this is all, but if you run into trouble I can help you diagnose it.
R
Hi @brandonseydel
I am getting this error on browser
vendor-bundle.js:5778 GET http://localhost:8001/user-list/src/js/kam/app-bundle.jsnet::ERR_ABORTED
I have given path in aurelia-json
âoutputâ: â/home/nilakshi/nilakshi/uamproject/src/kam/static/js/kamâ
my django project is in nilakshi->uamproject, and aurelia-project is inside nilakshi->aurelia-project
I have a post that describes another way to integrate:
It doesnât use webpack, instead the Aurelia CLI built in bundle, similar strategy should world though.
This no longer seems to work.
First of all, it requires webpack-bundle-tracker, which emits a file called âwebpack-stats.jsonâ. This is a status file that django-webpack-loader requires. It will (I suppose) have nested objects in it named âappâ, âvendorâ, etc, however, Iâm only seeing an âappâ section.
Note: the examples in django-webpack-loader README use âmainâ rather than âappâ, which doesnât work.
Next, when I get everything set up (point BUNDLE_DIR_NAME, STAT_FILE, etc in config/settings.py) and run this, it gives me this error:
string indices must be integers
Digging a bit, I see that it is looking in webpack-stats.json to find the bundles under the nested âappâ objected, in a further nested object called âchunksâ. My webpack-stats.json fileâs chunks are just a list of file names. But, in the django-webpack-loader code, we have (in webpack_loader, line 42):
for chunk in chunks:
ignore = any(regex.match(chunk['name']) âŠ
But, âchunkâ at this point isnât an object with a name attribute; itâs just a string. So this dereference fails. Maybe the elements of âchunksâ at one time were themselves objects and this has since changed. Or, thereâs a command line switch to make the generated webpack-stats.json file use that form. If so, thereâs no mention of it anywhere I can find on albeit cursory inspection.
Look, I really like Aurelia, but the bundler / loader moving targets are HUGELY frustrating. It really shouldnât be this hard.
Can this be an issue with some dependencies at a wrong version? I used django-webpack-loader
some months ago on a Django/React project and everything worked fine. From what I see in this issue and that one, newer versions of webpack-bundle-tracker
are not supported. You can try downgrading webpack-bundle-tracker
to see whether is solves the issue.
This project also doesnât seem very active (see here). So you can try switching to django-manifest-loader which has a similar scope (and is recommended at the bottom of the readme of django-webpack-loader
).
I hope this helps!