zoukankan      html  css  js  c++  java
  • webpack libray 参考例子

    备注:
      使用webpack 进行模块导出,方便进行通信
    1. 项目初始化
    ├── main.js
    ├── package.json
    ├── show.js
    ├── webpack.config.js
    └── yarn.lock
    2. 代码说明
    main.js
    
    const shortid = require("shortid");
    const demo = require("./show.js");
    module.exports = {
      shortid:function(){
       return shortid.generate();
      },
      printinfo:function(){
       demo();
      }
    };
    
    show.js
    function demo(content){
    window.document.getElementById("app").innerText="demo"+content;
    }
    module.exports=demo;
    
    package.json
    {
      "dependencies": {
        "shortid": "^2.2.8"
      },
      "scripts": {
        "build": "webpack"
      },
      "name": "@cnpm/dalong-demo",
      "version": "1.0.2",
      "main": "bundle.js",
      "license": "MIT"
    }
    
    webpack.config.js
    const path = require("path");
    module.exports = {
      entry:"./main.js",
      output:{
       filename:"bundle.js",
       path:path.resolve(__dirname,"./"),
       library:"dalongrong",
       libraryTarget:"commonjs2"
      }
    }
    3. 构建(同时发布私服)
    yarn && yarn run build && npm publish
    4. 使用
    yarn add @cnpm/dalong-demo
    app.js
    
    const myfirst = require("@cnpm/dalong-demo");
    console.log(myfirst.shortid())
    备注:
    实际上也普通的npm 模块开发是一样的,只不过使用使用了webpack 同时将对应的依赖打包在一起了
  • 相关阅读:
    第六周总结
    第五周总结
    第四周总结
    7-1 抓老鼠啊~亏了还是赚了?
    春季学期第八周作业
    春季学期第七周作业
    春季学期第六周作业
    春季学期第五周作业
    春季学期第四周作业
    春季学期第三周作业
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/8143094.html
Copyright © 2011-2022 走看看