1

How do I add a global JS file to the nuxt config?

module.exports = {
 /*
 ** Global CSS
 */
 css: ['~/assets/css/main.css'],
/*
** Global JS
*/
js: ['~/assets/js/main.js']

}

It does not work obviously.

any ideas?

5
  • What is the purpose of you global file ? XY problem suspected. Commented May 10, 2019 at 7:18
  • You would want to look at plugins. Commented May 10, 2019 at 7:45
  • @mathk i have JS folder and i need to link up with my nuxt project Commented May 10, 2019 at 11:00
  • @priyeshvadhiya Doing import ... as needed wouldn't work ? Commented May 10, 2019 at 11:54
  • @mathk not working Commented May 13, 2019 at 5:10

1 Answer 1

2

Simply keep your script.js file into static folder, because static folder treat as root folder.

and change nuxt.config.js configuration file like below

module.exports = {
//Global JS
script: [
        { src: '/script.js'}
        ]
........
..........

}

you can see another solution from here

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

1 Comment

you should keep your js file in root folder , because when you build Nuxt generate then global js file not place into root. so you have to do it manually. thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.