注意: 不支持导入需要node或者browser环境运行的包

cd /tmp

mkdir dependences

cd dependences

npm i -g webpack-cli    # 全局下载webpack-cli(打包工具)

npm i crypto-js    # 下载依赖包到本地

vim webpack.config.js  # 编辑webpack.config.js

npx webpack-cli -c webpack.config.js # 等价于npm run xxx, 执行webpack.config.js

cat dist/crypto-js | pbcopy    # 打包默认在dist目录下, 复制到剪切板
webpack.config.js

结构:

module.exports = {

      entry: './node_modules/${moduleName}/${moduleName.js}',

      output: {

        filename: '${moduleName.js}',

        library: '${moduleName}',

        libraryTarget: 'var'

      }

    }

如:

module.exports = {

  entry: './node_modules/crypto-js/crypto-js.js',

  output: {

    filename: 'crypto_js.js',

    library: 'crypto_js',

    libraryTarget: 'var'

  }

}

相当于require

在行为流的代码块中粘贴通过上方生成的包内容即可

Copyright © FunctorZ 2024 all right reserved修订时间: 2024-10-12 10:57:53

results matching ""

    No results matching ""