webpack.prod.config.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const merge = require('webpack-merge')
  2. const path = require('path')
  3. const webpack = require('webpack')
  4. const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  6. const baseConfig = require('./webpack.config')
  7. const { getThemeVariables } = require('antd/dist/theme')
  8. module.exports = merge(baseConfig, {
  9. entry: {
  10. index: path.resolve(__dirname, '../src/index.tsx'),
  11. publicity: path.resolve(__dirname, '../src/publicity.tsx'),
  12. },
  13. output: {
  14. publicPath: '/',
  15. filename: 'static/js/[name].[hash:8].js',
  16. chunkFilename: 'static/js/[name].[hash:8].chunk.js',
  17. path: path.resolve(__dirname, '../dist'),
  18. },
  19. mode: 'production',
  20. devtool: false,
  21. module: {
  22. rules: [
  23. {
  24. test: /\.less$/,
  25. use: [
  26. {
  27. loader: MiniCssExtractPlugin.loader,
  28. },
  29. {
  30. loader: 'css-loader', // translates CSS into CommonJS
  31. },
  32. {
  33. loader: 'less-loader', // compiles Less to CSS
  34. options: {
  35. lessOptions: {
  36. javascriptEnabled: true,
  37. },
  38. },
  39. },
  40. ],
  41. },
  42. {
  43. test: /\.scss$/i,
  44. use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
  45. exclude: path.resolve(__dirname, '../node_modules'),
  46. },
  47. {
  48. test: /\.css$/i,
  49. use: [MiniCssExtractPlugin.loader, 'css-loader'],
  50. },
  51. ],
  52. },
  53. plugins: [
  54. new webpack.DefinePlugin({
  55. 'process.env.NODE_ENV': JSON.stringify('production'),
  56. }),
  57. new MiniCssExtractPlugin({
  58. // Options similar to the same options in webpackOptions.output
  59. // both options are optional
  60. filename: 'static/css/[name].[contenthash:8].css',
  61. chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
  62. }),
  63. ],
  64. })