No Description

webpack.config.umd.js 944B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const path = require('path');
  2. const prodConfig = require('./webpack.config.prod');
  3. const rootPath = process.cwd();
  4. const plugins = [...prodConfig.plugins];
  5. // 移除 CopyWebpackPlugin 与 HtmlWebpackPlugin
  6. plugins.pop();
  7. plugins.pop();
  8. const umdConfig = {
  9. ...prodConfig,
  10. output: {
  11. filename: '[name].js',
  12. path: path.resolve(rootPath, './dist'),
  13. // 默认不允许挂载在全局变量下
  14. // library: library,
  15. libraryTarget: 'umd'
  16. },
  17. externals: {
  18. // Don't bundle react or react-dom
  19. react: {
  20. commonjs: 'react',
  21. commonjs2: 'react',
  22. amd: 'React',
  23. root: 'React'
  24. },
  25. 'react-dom': {
  26. commonjs: 'react-dom',
  27. commonjs2: 'react-dom',
  28. amd: 'ReactDOM',
  29. root: 'ReactDOM'
  30. },
  31. 'styled-components': {
  32. commonjs: 'styled-components',
  33. commonjs2: 'styled-components'
  34. }
  35. },
  36. plugins
  37. };
  38. delete umdConfig.optimization;
  39. module.exports = umdConfig;