webpack.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const webpack = require('webpack');
  2. const pkg = require('./package.json');
  3. const path = require('path');
  4. const TerserPlugin = require('terser-webpack-plugin');
  5. let config = {
  6. entry: './src/index.js',
  7. output: {
  8. filename: 'flv.js',
  9. path: path.resolve(__dirname, 'dist'),
  10. library: 'flvjs',
  11. libraryTarget: 'umd',
  12. environment: {
  13. arrowFunction: false,
  14. bigIntLiteral: false,
  15. const: false,
  16. destructuring: false,
  17. dynamicImport: false,
  18. forOf: false,
  19. module: false
  20. }
  21. },
  22. devtool: 'source-map',
  23. resolve: {
  24. extensions: ['.ts', '.tsx', '.js', '.json'],
  25. fallback: {
  26. fs: false,
  27. path: false
  28. }
  29. },
  30. plugins: [
  31. new webpack.DefinePlugin({
  32. __VERSION__: JSON.stringify(pkg.version)
  33. })
  34. ],
  35. optimization: {
  36. minimizer: [
  37. new TerserPlugin({
  38. extractComments: false,
  39. })
  40. ]
  41. },
  42. module: {
  43. rules: [
  44. {
  45. test: /\.(ts|js)$/,
  46. use: 'ts-loader',
  47. exclude: /node-modules/
  48. },
  49. {
  50. enforce: 'pre',
  51. test: /\.js$/,
  52. use: 'source-map-loader'
  53. }
  54. ]
  55. }
  56. };
  57. module.exports = (env, argv) => {
  58. if (argv.mode === 'production') {
  59. config.output.filename = 'flv.min.js';
  60. }
  61. return config;
  62. };