webpack mangle选项已更改umd库名称

时间:2018-06-28 15:17:25

标签: javascript webpack uglifyjs

我想创建一个umd库并对其进行丑化,当我使用以下选项对其进行丑化时,它更改了我的库API名称,

module.exports = {
  entry: [
    './JS/example/index.js'
 ],
  //devtool: 'inline-source-map',
  //devtool:'source-map',
  plugins: [

    new CleanWebpackPlugin(['dist'])
  ],

  mode: 'production',

  module: {
   rules: [
     {
      test: /\.js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: ['es2015'],
          plugins: [],
        }
      }
    }
   ]
  },

  output: {
    path: path.resolve(__dirname, 'JS/example/dist/umd'),
    library: "GlobeApi",
    libraryTarget: 'umd',
    umdNamedDefine: true

  },
  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions:{
          compress:{ecma:5},
          mangle:{
            "properties":true,
            "reserved":['Draw', 'mylibrary','myapi'],
            "keep_fnames": true,
            "keep_classnames": true,
          },
          output: {
            comments: false,
          },

        }
      }),
    ]
  }

};

它是这样导出的:
    s:对象{ah:CSGlobe(),…} 在Class对象原型函数中未定义,我尝试使用导出的类,但是它给出了类型错误obj t.eb的定义。

我尝试了很多方法,但是当我添加属性修改选项时,即使保留了它也会修改所有内容。

软件包版本:

“ babel-preset-es2015”:“ ^ 6.24.1”

“ uglifyjs-webpack-plugin”:“ ^ 1.2.7”

“ webpack”:“ ^ 4.4.1”

0 个答案:

没有答案