3

I have created a Vue project with Typescript having components in class style. I need to include some external CSS file - like from Amazon S3. The CSS doesn't seems to be loaded.

In the network section I can see it.

enter image description here

3
  • 1
    Can you post how you included the CSS file, And how did you created project ? Did you used vue-cli or ? Commented Aug 28, 2019 at 6:53
  • Yes I used vue-cli. I included Babel, TS, TSlint, ... I included simply using <link rel="stylesheet" href=""> in index.html Updated my question Commented Aug 28, 2019 at 6:55
  • Possible duplicate of How to include css files in Vue 2 Commented Aug 28, 2019 at 7:07

2 Answers 2

10

you can load external URL

<style lang="scss or less">
    @import "https://external_url_.css";
    @import ".../assest/_.css";
</style>

you can load css loaders installed if you more such as sass-loader, css-loader , less-loader npm

Sign up to request clarification or add additional context in comments.

2 Comments

I have installed "css-loader": "^3.2.0", Do I need to configure anywhere.
not need just tr. if you plan to use less or scss (preprocessor) you can move with preprocessor loader. that's your preference.
7

I suggest you to use preprocessor

Install SASS -

npm install -D sass-loader sass

then You will be able to import it in your App.vue

<style lang="scss">
@import './static/css/style.css';
</style>

Update

I figured out one more way to include single css file.

In your App.vue, you can add css file to style src

<style src="relative-path/style.css"></style>

7 Comments

Why I need to use scss here. It's CSS file only ryt
Correct, but dynamic imports requires scss. This way you can even control individual css imports to single component too. There is JS way too using webpack but I recommend SASS here neat and helpful. In future you probably want to use scss
that's optional
Didn't work for me after installing sass <style lang="scss"> @import url('<some_url>'); </style>
Yes I installed sass. I placed the above line in App.vue
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.