question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should I import CSS in js file?

See original GitHub issue

I use iview in my project, in renderer process like this:

import iView from 'iview';
import 'iview/dist/styles/iview.css';    // Use CSS

Vue.use(iView);

But, there is a error in console:

Uncaught SyntaxError: Unexpected token .
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.require.extensions.(anonymous function) [as .js] (D:\Projects\demo\node_modules\electron-compile\lib\require-hook.js:77:14)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Projects\demo\src\renderer.js:32:1)
    at Object.<anonymous> (D:\Projects\demo\src\renderer.js:72:3)

Should I use import .css file in .js file without webpack?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
MarshallOfSoundcommented, Aug 7, 2017

You shouldn’t import CSS in a JS file in any circumstance IMO. WebPack uses that technique as a result of CSS modules and it just working better with their bundling strategy (plus a bunch of other reasons I’m sure).

But in a world where you don’t need to bundle and your entire browser is a commonJS environment, including CSS in JS makes very little sense. You should just add a link tag for it 👍

10reactions
mnemanjacommented, Oct 19, 2017

What happens with React? Which approach do would you suggest for importing css in react components?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Many Ways to Include CSS in JavaScript Applications
CSS-in-JS frameworks do this by outputting that CSS within a <style> tag in the <head> of your application. This gives you a critical...
Read more >
How to load up CSS files using Javascript? - Stack Overflow
P.S the javascript will be hosted on my site, but I want users to be able to put in the <head> tag of...
Read more >
Should I load CSS in the main JavaScript file? - Quora
No. You are expected to style with CSS. JavaScript is for interactivity and anything that needs to be programmed or scripted. Both CSS...
Read more >
How to load CSS files using JavaScript? - GeeksforGeeks
How to load CSS files using JavaScript? · Use document.getElementsByTagName() method to get HTML head element. · Create new link element using ...
Read more >
Using CSS Module Scripts to import stylesheets - web.dev
Learn how to use CSS module scripts to import CSS stylesheets using the same syntax as JavaScript modules.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found