[英]Using Node package in NativeScript app
I am learning NativeScript. 我正在学习NativeScript。 For example, I would like to include this Guid generator package in my NativeScript app.
例如,我想在我的NativeScript应用程序中包含这个Guid生成器包 。 My question is, how?
我的问题是,如何? I look at the directory structure generated by the command-line tool and I see the following relevant pieces:
我看一下命令行工具生成的目录结构,并看到以下相关内容:
node_modules
app
tns_modules
package.json
package.json
Do I add node-uuid
to the ./package.json or the ./app/package.json? 是否将
node-uuid
添加到./package.json或./app/package.json? How do I reference it in my app then? 那我该如何在我的应用程序中引用它? For example, if I want to use uuid from the app.js file, what does that look like?
例如,如果我想使用app.js文件中的uuid,那会是什么样? I'm a little confused because of the package structure of NativeScript and how things actually get loaded at runtime.
由于NativeScript的包结构以及运行时如何实际加载,我有些困惑。
Thanks 谢谢
Run npm install from the root of your {N} app. 从您的{N}应用的根目录运行npm install。
npm install --save node-uuid
The dependency will be added to the outer package.json. 该依赖项将添加到外部package.json中。
And then in your app.js file, just use it like usual. 然后在您的app.js文件中,像往常一样使用它。
var uuid = require('node-uuid');
When you run tns run <platform>
or tns build <platform>
, the modules inside node_modules/
will be copied to folder under platforms/
, take Android for example, it will be at platforms/android/assets/app/tns_modules/node-uuid
. 当您运行
tns run <platform>
或tns build <platform>
, node_modules/
内部的模块将被复制到platforms/
下的文件夹中,例如Android,它将位于platforms/android/assets/app/tns_modules/node-uuid
。 The building process is completed under platforms/
directory. 构建过程在
platforms/
目录下完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.