webpack.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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://clipboardjs.com/
  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. globalObject: 'this',
  17. libraryExport: 'default',
  18. libraryTarget: 'umd'
  19. },
  20. module: {
  21. rules: [
  22. {test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
  23. ]
  24. },
  25. optimization: {
  26. minimize: production,
  27. minimizer: [
  28. new UglifyJSPlugin({
  29. parallel: require('os').cpus().length,
  30. uglifyOptions: {
  31. ie8: false,
  32. keep_fnames: false,
  33. output: {
  34. beautify: false,
  35. comments: (node, {value, type}) => type == 'comment2' && value.startsWith('!')
  36. }
  37. }
  38. })
  39. ]
  40. },
  41. plugins: [new webpack.BannerPlugin({ banner })]
  42. };