NPM:将多个模块和自定义脚本与browserfy相结合

NPM: combining multiple modules and custom scripts with browserify

本文关键字:脚本 自定义 browserfy 相结合 模块 NPM      更新时间:2024-03-06

我的package.json中有以下脚本:

  "scripts": {
    "bundle": "browserify index.js > js/bundle.js"
  },

index.js不包含任何内容,只有我包含的npm模块被绑定到bundle.js.中

我想知道接下来合乎逻辑的步骤是什么?

前提条件:

  • 保持项目模块化
  • 将npm模块+自定义脚本组合成一个bundle.js

这可以通过使用npm作为构建工具来实现吗?

下一个逻辑步骤是开始在index.js中编写代码,但该逻辑是基于您想要编写自己的模块的假设。

首先,您需要在package.jsondependencies字段中设置任何模块。然后,您将通过module.exports公开代码。

示例:

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 */
}

我是不是错过了什么?