I have static files in django call it A.js and B.js
in A.js
I have for example for constant like
const variable = "Hello, World"
export {variable}
in B.js
I have:
import {variable} from './A.js'
Kindly note that both files are in the static files directory of django project.
My question is how am I going to import successfully the variable so that it checks into variable and use them in the template without getting exceptions
Uncaught SyntaxError: Unexpected token ‘export’ and the whole JS does not work
I also needed to declare them as modules inside the template
<script src='{% static "js/A.js" %}' type="module" ></script>
<script src='{% static "js/B.js" %}' type="module" ></script>
either ways not working. I have previously used export default
approach , still not working
2
Answers
Okay guys I found that django does not require webpacks import or export statement in order to access javascript variables, Remember the `**
**` , it does the job of managing or you can also say bundling your django static files into a single file
In ruby on rails , there is an application.js or application.css, which is a root of all the other javascripts or css file within the assets folder of the rails framework
In a similar way, django does not specify a single file but its designed to automatically make all the files in a static folder visible to each other
thus without any import statement or export statement I can easily call the variable in B.js which is defined in A.js
Try doing
instead of