1

I am using some 3rd party JS file which uses an import statement inside the JS file itself. I am using Django, and that css file is in STATICFILES_DIRS, which I can access through {% static 'css/main.css' %}. This is the file being imported.

In js this is being imported something like this

import '../../css/main.css'

I have declared a variable in index.html that holds this value

index.html

<script type="text/javascript">
    const main_css = "{% static 'css/main.css' %}"
</script>

In my main.js file I am using this syntax

@import `${main_css}`

which doesn't work, the DOM doesn't change. Any tips?

Sahil
  • 1,387
  • 14
  • 41
  • 1
    You can't import a javascript file directly in javascript, ECMAScript only supports module importing. @import statements work when you pre-process your files with webpack or bower or something similar. – dirkgroten Jan 09 '20 at 11:37

0 Answers0