webpack.config.js 1.2 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. target: ['web', 'es5'],
  13. output: {
  14. filename: production ? 'clipboard.min.js' : 'clipboard.js',
  15. path: path.resolve(__dirname, 'dist'),
  16. library: 'ClipboardJS',
  17. globalObject: 'this',
  18. libraryExport: 'default',
  19. libraryTarget: 'umd',
  20. },
  21. module: {
  22. rules: [{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' }],
  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 }) =>
  35. type == 'comment2' && value.startsWith('!'),
  36. },
  37. },
  38. }),
  39. ],
  40. },
  41. plugins: [new webpack.BannerPlugin({ banner })],
  42. };