Should I import CSS in js file?
See original GitHub issueI 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:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 👍What happens with React? Which approach do would you suggest for importing css in react components?