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'
})
]
},
}
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.
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.
This option lets you configure various settings for the build step, including loaders , filenames , the webpack config and transpilation .
~ 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' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With