[英]NPM: combining multiple modules and custom scripts with browserify
I have a following script in my package.json: 我的package.json中有以下脚本:
"scripts": {
"bundle": "browserify index.js > js/bundle.js"
},
index.js contains nothing and only my npm-included modules are bundled into bundle.js. index.js什么都不包含,只有我的npm包含的模块被捆绑到bundle.js中。
I am wondering what's the next logical step to go from here? 我想知道从这里开始的下一个合乎逻辑的步骤是什么?
Prequisities: Prequisities:
Can this be done by using npm as a build tool? 这可以通过使用npm作为构建工具来完成吗?
The next logical step is to start writing code in your index.js - but that logic is based on the assumption that you want to write your own module. 下一个逻辑步骤是开始在index.js中编写代码 - 但该逻辑基于您想要编写自己的模块的假设。
To kick things off, you would require whatever modules were set in your dependencies
field in the package.json . 为了解决问题,您需要在package.json中的
dependencies
字段中设置任何模块。 You would then expose your code via module.exports
. 然后,您将通过
module.exports
公开您的代码。
Example: 例:
var someModule = require('some-module'); /* some external module */
module.exports = MyModule; /* expose your module */
function MyModule () {
console.log('Hello World!');
/* do something! */
someModule(); /* example of using external modules within yours */
}
Am I missing something? 我错过了什么吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.