webpack.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const pkg = require('./package.json');
  2. const path = require('path');
  3. const webpack = require('webpack');
  4. const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
  5. const production = process.env.NODE_ENV === 'production' || false;
  6. const banner = `clipboard.js v${pkg.version}
  7. https://zenorocha.github.io/clipboard.js
  8. Licensed MIT © Zeno Rocha`;
  9. module.exports = {
  10. entry: './src/clipboard.js',
  11. mode: 'production',
  12. output: {
  13. filename: production ? 'clipboard.min.js' : 'clipboard.js',
  14. path: path.resolve(__dirname, 'dist'),
  15. library: 'ClipboardJS',
  16. libraryTarget: 'umd',
  17. globalObject: 'this'
  18. },
  19. module: {
  20. rules: [
  21. {test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
  22. ]
  23. },
  24. optimization: {
  25. minimize: production,
  26. minimizer: [
  27. new UglifyJSPlugin({
  28. parallel: require('os').cpus().length,
  29. uglifyOptions: {
  30. ie8: false,
  31. keep_fnames: false,
  32. output: {
  33. beautify: false,
  34. comments: (node, {value, type}) => type == 'comment2' && value.startsWith('!')
  35. }
  36. }
  37. })
  38. ]
  39. },
  40. plugins: [new webpack.BannerPlugin({ banner })]
  41. };