1

I have a couple of js and css files which were custom built and i want to include that into my vue cli3 project. Is there any way to import those files into my project ?

2
  • import x from y? Commented Feb 13, 2019 at 13:32
  • may be you can import it in index file Commented Feb 13, 2019 at 13:33

3 Answers 3

1

For custom js files, write all your logic in a object and export it at the end of the file :

const customJs = {
   /* custom javascript here */
}

export default customJs;

and then import it where you need it as :

import * as customJs from '../path/to/file.js'

For custom css files, you can use @import between the style tags like this:

@import './../node_modules/foo/bar.css';
Sign up to request clarification or add additional context in comments.

1 Comment

Do consider upvoting the answer as well, if it was helpful :)
1

You can use a pre-processor when creating the project with vue-cli.

See: Working with CSS

Or if you don't need a pre-processor and you are using CSS modules you can go for this route

See: CSS Modules

As for JavaScript it's pretty straight forward if you are on ES2016/ES6 just use the syntax

import tool from 'toolmodulename';

Comments

1

Try this in main.js

import "path-your-css/your-css.css";

Comments

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.