使用browserify在浏览器中提供包

时间:2018-06-01 15:16:11

标签: browserify commonjs

我不太确定如何做到这一点:

我有一个小程序包,其中包含一些实用程序功能,我想为节点和浏览器提供这些功能。

的package.json

{
  "name": "test-broserify-package",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "browserify": "browserify index.js > bundle.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "browserify": "^16.2.2"
  }
}

index.js

module.exports = {
    someFunction: function someFunction() {
        return "some content";
    }
}

的index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>usage</title>
    <script src="../package/bundle.js"></script>
</head>

<body>
    <script>
        const testBroserifyPackage = require('test-broserify-package');
        console.log(testBroserifyPackage.someFunction());
    </script>
</body>

</html>

捆绑软件包的适当命令是什么,以便它可以如图所示使用?

0 个答案:

没有答案