zoukankan      html  css  js  c++  java
  • 把@okexchain/javascript-sdk打包为一个文件给第三方

    缘由:部分合作伙伴(没错,就是ont)并不想下载我们的jssdk库,只想把它汇总为一个js文件,我想大概率对方应该接了很多家的jssdk,每家一个sdk文件,干净好管理。

    解决:在1月底的时候解决过一次,但在3月初就全忘记了,没一点印象。

    几经周折,终于找到解决办法了。

    位置:打开opendex-ui工程

    (我自己的opendex-ui工程在github/okex/opendex-ui下,已经存在,所以不需要安装)

    把webpack.config.sdk.js和index.js两个文件分别按如下位置放置:

    ./build/webpack.config.sdk.js

    ./src/index.js

    在package.json的scripts中添加

    "web-sdk": "cross-env NODE_ENV=production webpack --config build/webpack.config.sdk.js",

    得到压缩后的文件:

    运行 $ npm run web-sdk

    生成的目标文件在 ./dist/okexchain-sdk.js

    附1:webpack.config.sdk.js

    const path = require('path');
    const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
    const base = {
      entry: path.resolve(__dirname, `../src/index.js`),
      output: {
        filename: 'okexchain-sdk.js',
        library:'OKExChainClient',
        libraryTarget:'global'
      },
      module: {
        rules: [
          {
            test: /.js$/,
            use: [
              {
                loader: 'babel-loader',
                options: {
                  presets: ['@babel/preset-react'],
                  plugins: [
                    ['@babel/plugin-proposal-decorators', { legacy: true }],
                    ['@babel/plugin-proposal-class-properties', { loose: true }],
                  ],
                },
              },
            ],
          },
        ],
      },
      optimization: {
        minimizer: [
          new UglifyJsPlugin({
            cache: true,
            parallel: true,
            uglifyOptions: {
              compress: {
                warnings: false,
                drop_console: true,
                collapse_vars: true,
                reduce_vars: true,
              },
            },
          }),
        ],
      }
    };
    
    module.exports = base;

    附2:index.js

    const OKExChainClient = require('@okexchain/javascript-sdk');
    module.exports = OKExChainClient;
  • 相关阅读:
    PerfDog WEB端使用手册
    PerfDog4.0探索,支持用户自建web云
    无AI不测试:人工智能时代背景下,如何发展与应用自动化测试?
    性能测试实践 | PerfDog助力微信小游戏/小程序性能调优
    mysql面向过程学习
    阿里云操作记录
    socket网络编程
    学习慕课广告系统
    xinhuadouxxx总结
    maven+springboot+mybatis快速搭建简单使用
  • 原文地址:https://www.cnblogs.com/zccst/p/14473430.html
Copyright © 2011-2022 走看看