Support the ongoing development of Laravel.io →
Views Packages

Hey, i want to use for some of my scripts (inside blade template view) modules that come as npm, using npm install. but i am a bit confused on how to use them inside my app? i know they are supposed to work with node,js app, but is there an alternative to the 'require(module-name)' that allows me to use it in my views?

thanks

Last updated 3 years ago.
0

I don't think this is completely impossible, it's overall JavaScript, why now? :D

But do notice that node.js is a runtime environment that uses JavaScript as its language. There are certainly packages using its core modules, and I bet it's going to be hard as some of the packages are targeting only to node environment.

Some of the packages such as jQuery, moment.js are capable working on both client and server version, some even provide 2 different versions, one for client, one for server, so you can definitely do npm install jquery and include them from your node_modules folder like how you would normally include your script.

You could also take a look at these,

PS: If they have a client-side, it could also be available on Bower, the "client-side" npm.

PS2: If you would like to "require" libraries like you do on node, you could try to use AMD RequireJS as well. It provides similar syntax as CommonJS

Last updated 10 years ago.
0

if you're using npm packages on views better switch to bower because npm is not made for inclusion on views. It will work on some but some packages will not work like that.

Last updated 10 years ago.
0

so i have to use bower and install extra js libraries like require etc?

i will have a look on bower website. thanks!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

avieln avieln Joined 29 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.