webpack.config.prod.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. const path = require('path')
  18. const webpack = require('webpack')
  19. const merge = require('webpack-merge')
  20. const CopyWebpackPlugin = require('copy-webpack-plugin')
  21. const { baseConfig } = require('./config')
  22. const TerserPlugin = require('terser-webpack-plugin')
  23. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  24. const ProgressPlugin = require('progress-bar-webpack-plugin')
  25. const resolve = dir =>
  26. path.resolve(__dirname, '..', dir)
  27. const config = merge.smart(baseConfig, {
  28. devtool: 'source-map',
  29. output: {
  30. filename: 'js/[name].[chunkhash:7].js'
  31. },
  32. plugins: [
  33. new ProgressPlugin(),
  34. new MiniCssExtractPlugin({ filename: 'css/[name].[contenthash:7].css' }),
  35. new webpack.optimize.OccurrenceOrderPlugin(),
  36. new CopyWebpackPlugin([
  37. {
  38. from: resolve('src/lib'),
  39. to: resolve('dist/lib')
  40. },
  41. {
  42. from: resolve('src/images'),
  43. to: resolve('dist/images')
  44. },
  45. ]),
  46. ],
  47. optimization: {
  48. minimize: true,
  49. minimizer: [
  50. new TerserPlugin({
  51. terserOptions: {
  52. compress: {}
  53. },
  54. cache: true,
  55. parallel: true,
  56. sourceMap: false,
  57. exclude: /node_modules/,
  58. extractComments: (astNode, comment) => {
  59. if (/^!|@preserve|@license|@cc_on|MIT/i.test(comment.value)) {
  60. return true
  61. }
  62. return false
  63. }
  64. }),
  65. ],
  66. sideEffects: true
  67. },
  68. mode: 'production'
  69. })
  70. module.exports = config