How to reference Library Knockout.js installed via NPM

Asked

Viewed 54 times

2

I installed the Knockout.js library via NPM, by the following command:

npm install --save-dev knockout

I noticed that NPM installs the module inside the node_modules/knockout folder, but I believe there is a way to include the script in the project without having to refer it to the following path in my index.html:

<script src="node_modules/knockout/build/output/knockout-lastest.js></script>

How do I include it in the right way?

  • Where are you wearing the Knockout? you have some compiler like webpack, Browserify?

  • not @Sergio. I just installed via NPM. I must install the webpack and call the package there?

  • In that case, it seems more like "old-fashioned" NDC. If you want to hide possible global variables from Knockout.js you can use one of these compilers/packers or require.js. But you’ll be adding complexity that can only get in the way...

  • I got it.. I wanted to use via NPM just to try it out. But I agree with you that maybe it doesn’t pay to leave complex something that can be simpler. Thanks for your help, @Sergio

  • You’re welcome. Yeah, it’s always good to try it. And you can use it locally by going to node_modules. Where is your HTML file compared to node_modules? You have a server or are testing locally?

  • I’m using it locally. The index is inside the "source" folder. Going back one level, comes the node_modules folder at the project root. My goal is to create a folder with project editing files, and another publication folder, called "dist", where I will include, after running Grunt, all the files from the minified and concatenated source folder.

  • To use Knockout.js via node_modules can do <script src="../node_modules/knockout/build/output/knockout-lastest.js></script> if I have understood the structure of the directories well. You could have Grunt fetch that file from node_modules and use from dist also... several options :)

  • Beauty @Sergio! Thank you so much ;)

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.