I have added package onesignal-emoji-picker to my nuxt.js vue project and I want to reference css and js files in my pages without copying them to static folder. css is included with ease in nuxt.config.js
:
css: ['~/node_modules/onesignal-emoji-picker/lib/css/emoji.css']
but I could not manage to reference js files, head.script
section seems to work only for external resources:
script: [
{
src: 'https://code.jquery.com/jquery-3.3.1.slim.min.js',
type: 'text/javascript'
},
{
src: '~/node_modules/onesignal-emoji-picker/lib/js/config.js',
type: 'text/javascript'
},
{
src: '~/node_modules/onesignal-emoji-picker/lib/js/util.js',
type: 'text/javascript'
},
{
src: '~/node_modules/onesignal-emoji-picker/lib/js/jquery.emojiarea.js',
type: 'text/javascript'
},
{
src: '~/node_modules/onesignal-emoji-picker/lib/js/emoji-picker.js',
type: 'text/javascript'
}
]
It seems to me that I should somehow tell webpack to include this files on build and reference them appropriately? How could I do it? Thanks!
It's only right that Nuxt 3 was built to support Vue 3 features. Vue 3 was released in October 2020 and has since garnered a lot of praise from the Vue community. With Nuxt 3 being written in Vue 3, you get access to features like the Composition API, better module imports, and overall improved app performance.
If you want to change the port number temporarily, you can do it by adding a --port option to the npm run dev command.
In nuxt.config.js
, simply use the plugins
key for including any internal scripts:
plugins: [
{ src: "~/node_modules/onesignal-emoji-picker/lib/js/config.js", mode: "client" },
{ src: "~/node_modules/onesignal-emoji-picker/lib/js/util.js", mode: "client" },
{ src: "~/node_modules/onesignal-emoji-picker/lib/js/jquery.emojiarea.js", mode: "client" },
{ src: "~/node_modules/onesignal-emoji-picker/lib/js/emoji-picker.js", mode: "client" }
]
Note the mode: "client"
option which means the files will only be run on the client, preventing issues on the server if the library is not compatible with server-side-rendering. You may want to remove the flag in other cases.
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