Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding js files to nuxt config

Someone designed the front end of my web page and now I am trying to use all the .css and .js files globally for all my pages in nuxtjs. But I am failing to include the files correctly.

This is one of the files I am trying to include: jquery.themepunch.tools.min.js. I get this error:

{ statusCode: 404, path: '/~/assets/revolution/js/jquery.themepunch.tools.min.js', message: 'This page could not be found' }

I added the path to the file into my nuxt.js.config, but I can't figure out what I am missing here. Here is my config file:

const webpack = require('webpack')

module.exports = {
  head: {
    title: 'test-webpage',

    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'test page' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],
    script: [
      {src: '~/assets/revolution/js/jquery.themepunch.tools.min.js'}
    ]
  },

  build: {
    vendor: ['jquery', 'bootstrap'],
    plugins: [
      // set shortcuts as global for bootstrap
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery'
      })
    ]
  },
}
like image 363
cjs Avatar asked Jun 26 '18 10:06

cjs


People also ask

How add external js to Nuxt?

Add External script links in Nuxt components. In Nuxt you can use head as a function or as an Object. By using it as a function, it will provide us access to data and computed property. That's how you can add external scripts in your component / page. If you want to add multiple scripts just add it inside the array.

How do I add components to Nuxt?

To dynamically import a component, also known as lazy loading a component, all you need to do is add the Lazy prefix in your templates. Using the lazy prefix you can also dynamically import a component when an event is triggered.

What is Nuxt config js used for?

This option lets you configure various settings for the build step, including loaders , filenames , the webpack config and transpilation .


1 Answers

~ is alias for webpack building. head is used for loading external script, script will not be included in bundled js.

You can move jquery.themepunch.tools.min.js into static and change script to

{ src: '/urpathinsidestaticfolder/jquery.themepunch.tools.min.js' }
like image 143
Aldarund Avatar answered Oct 10 '22 03:10

Aldarund