3

I use Vue-cli with webpack, and I have problem to call external js and css file in index.html.

enter image description here

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>gradana</title>
    <link rel="stylesheet" href="./src/assets/css/hello.css">
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

If I run the code I have error.

enter image description here

Cannot GET /src/assets/css/hello.css
1
  • 1
    I found solution : I add code in App.vue <style> @import './assets/css/hello.css'; Commented Apr 5, 2017 at 5:10

1 Answer 1

2

As you are using vue cli, assets folder will be handled by webpack during bundling, and those files within assets folder should be included by js

e.g. require('../node_modules/bootstrap/dist/css/bootstrap.min.css').

Or you can simply store CSS or JS files into /static folder, all files within static folder will be added into /dist folder while running app.

enter image description here

and then call it into index.html

CSS

<link rel="stylesheet" href="/static/css/hello.css">

JS

<script src="/static/scripts/script.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

but this does not work after creating build i tried the same but i got 404 after generation of build any solution to that?

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.