webpack.prod.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const path = require('path');
  2. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  3. const webpack = require('webpack');
  4. const happyPack = require('happypack');
  5. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  6. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  7. module.exports = {
  8. mode: 'production',
  9. entry: {},
  10. output: {
  11. filename: '[name]_[hash:8].js',
  12. path: path.join(__dirname, '../dist'),
  13. publicPath: '../../../../',
  14. library: '[name]',
  15. libraryTarget: 'umd',
  16. chunkFilename: '[name].js'
  17. },
  18. devtool: 'source-map',
  19. externals: {
  20. 'react': 'React',
  21. 'react-dom': 'ReactDOM',
  22. 'react-router': 'ReactRouter',
  23. 'redux': 'Redux',
  24. 'react-redux': 'ReactRedux',
  25. 'axios': 'axios',
  26. 'nc-lightapp-front': 'nc-lightapp-front',
  27. 'nc-report': 'nc-report',
  28. 'nc-hr-report': 'nc-hr-report',
  29. 'platform-login': 'platform-login'
  30. },
  31. resolve: {
  32. extensions: ['.js', '.jsx'],
  33. alias: {
  34. 'src': path.resolve(__dirname, '../src/')
  35. }
  36. },
  37. module: {
  38. rules: [{
  39. test: /\.(jsx|js)$/,
  40. exclude: /node_modules/,
  41. use: {
  42. loader: 'happypack/loader',
  43. options: {
  44. presets: ['env', 'react'],
  45. plugins: [
  46. ['import-bee', {
  47. "style": true
  48. }],
  49. 'transform-class-properties'
  50. ]
  51. }
  52. }
  53. }, {
  54. test: /\.less$/,
  55. exclude: /node_modules/,
  56. use: [
  57. MiniCssExtractPlugin.loader,
  58. 'css-loader',
  59. 'postcss-loader',
  60. 'less-loader'
  61. ]
  62. }, {
  63. test: /\.css$/,
  64. exclude: /node_modules/,
  65. use: [
  66. MiniCssExtractPlugin.loader,
  67. {
  68. loader: 'css-loader',
  69. options: {
  70. mode: 'local',
  71. modules: true,
  72. localIdentName: '[name]--[local]--[hash:base64:5]'
  73. }
  74. },
  75. 'postcss-loader'
  76. ]
  77. },
  78. {
  79. test: /\.css$/,
  80. include: /node_modules/,
  81. use: [
  82. MiniCssExtractPlugin.loader,
  83. {
  84. loader: 'css-loader',
  85. options: {
  86. modules: false,
  87. }
  88. },
  89. 'postcss-loader',
  90. ]
  91. }, {
  92. test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz|xlsx)(\?.+)?$/,
  93. exclude: /favicon\.png$/,
  94. use: [{
  95. loader: 'url-loader'
  96. }]
  97. }]
  98. },
  99. plugins: [
  100. new MiniCssExtractPlugin({
  101. // filename: '[name]_[contenthash:8].css'
  102. filename: '[name]_[hash:8].css' // 和js文件hash保持一致吧
  103. }),
  104. new happyPack({
  105. loaders: ['babel-loader']
  106. }),
  107. new OptimizeCssAssetsPlugin()
  108. ],
  109. stats: 'errors-only'
  110. };