webpack.config.prod.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 ExtractTextPlugin = require('extract-text-webpack-plugin')
  23. const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
  24. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  25. const ProgressPlugin = require('./../src/lib/@fedor/progress-webpack-plugin')
  26. const resolve = dir =>
  27. path.resolve(__dirname, '..', dir)
  28. const config = merge.smart(baseConfig, {
  29. devtool: 'source-map',
  30. output: {
  31. filename: 'js/[name].[chunkhash:7].js'
  32. },
  33. module: {
  34. rules: [
  35. {
  36. test: /\.vue$/,
  37. loader: 'vue-loader',
  38. options: {
  39. hotReload: false // 开启热重载
  40. }
  41. },
  42. {
  43. test: /\.css$/,
  44. loader: ExtractTextPlugin.extract({
  45. use: [
  46. 'css-loader',
  47. {
  48. loader: 'postcss-loader',
  49. options: {
  50. plugins: (loader) => [
  51. require('autoprefixer')({
  52. 'browsers': [ '> 1%', 'last 3 versions', 'ie >= 9' ]
  53. }),
  54. require('cssnano')
  55. ]
  56. }
  57. }
  58. ],
  59. fallback: ['vue-style-loader']
  60. })
  61. },
  62. {
  63. test: /\.scss$/,
  64. loader: ExtractTextPlugin.extract({
  65. use: [
  66. 'css-loader',
  67. 'sass-loader',
  68. {
  69. loader: 'postcss-loader',
  70. options: {
  71. plugins: (loader) => [
  72. require('autoprefixer')({
  73. 'browsers': [ '> 1%', 'last 3 versions', 'ie >= 9' ]
  74. }),
  75. require('cssnano')
  76. ]
  77. }
  78. }
  79. ],
  80. fallback: ['vue-style-loader']
  81. })
  82. }
  83. ]
  84. },
  85. plugins: [
  86. new ProgressPlugin(),
  87. new ExtractTextPlugin({ filename: 'css/[name].[contenthash:7].css', allChunks: true }),
  88. new webpack.optimize.CommonsChunkPlugin({ name: 'common', filename: 'js/[name].[hash:7].js' }),
  89. new webpack.optimize.OccurrenceOrderPlugin(),
  90. new OptimizeCssAssetsPlugin({
  91. assetNameRegExp: /\.css$/g,
  92. cssProcessor: require('cssnano'),
  93. cssProcessorOptions: { discardComments: { removeAll: true } },
  94. canPrint: true
  95. }),
  96. new UglifyJSPlugin({
  97. parallel: true,
  98. sourceMap: true,
  99. uglifyOptions: {
  100. compress: {
  101. drop_console: true,
  102. drop_debugger: true
  103. },
  104. comments: function (n, c) {
  105. /*! IMPORTANT: Please preserve 3rd-party library license info, inspired from @allex/amd-build-worker/config/jsplumb.js */
  106. var text = c.value, type = c.type
  107. if (type === 'comment2') {
  108. return /^!|@preserve|@license|@cc_on|MIT/i.test(text)
  109. }
  110. }
  111. }
  112. }),
  113. new CopyWebpackPlugin([
  114. {
  115. from: resolve('src/combo'),
  116. to: resolve('dist/combo')
  117. },
  118. {
  119. from: resolve('src/lib'),
  120. to: resolve('dist/lib')
  121. },
  122. {
  123. from: resolve('src/images'),
  124. to: resolve('dist/images')
  125. },
  126. ]),
  127. ]
  128. })
  129. module.exports = config