webpack.config.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import path from 'path'
  2. import { Configuration, EnvironmentPlugin } from 'webpack'
  3. import 'webpack-dev-server'
  4. import TerserPlugin from 'terser-webpack-plugin'
  5. const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development'
  6. const config: Configuration = {
  7. mode,
  8. entry: path.join(__dirname, 'src', 'index.ts'),
  9. output: {
  10. clean: true,
  11. filename: 'js/index.js'
  12. },
  13. devtool: mode === 'development' ? 'inline-source-map' : false,
  14. module: {
  15. rules: [
  16. {
  17. test: /\.tsx?$/,
  18. use: 'ts-loader',
  19. exclude: /node_modules/
  20. }
  21. ]
  22. },
  23. devServer: {
  24. allowedHosts: 'all',
  25. open: true,
  26. port: 8100
  27. },
  28. resolve: {
  29. alias: {
  30. '@': path.resolve(__dirname, 'src')
  31. },
  32. extensions: ['.ts', '.tsx', '.js']
  33. },
  34. externals: {
  35. jquery: 'jQuery',
  36. clipboard: 'ClipboardJS'
  37. },
  38. optimization: {
  39. minimize: true,
  40. minimizer: [
  41. new TerserPlugin({
  42. parallel: true,
  43. terserOptions: {
  44. mangle: true
  45. }
  46. })
  47. ]
  48. },
  49. plugins: [
  50. new EnvironmentPlugin(['npm_package_name', 'npm_package_version'])
  51. ]
  52. }
  53. export default config