webpack.config.prod.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 ProgressPlugin = require('progress-bar-webpack-plugin')
  24. const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
  25. const OptimizeCssAssetsPlugin = require('optimize-css-assets-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 // Open hot overload
  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. overrideBrowserslist: [
  53. "Android 4.1",
  54. "iOS 7.1",
  55. "Chrome > 31",
  56. "ff > 31",
  57. "ie >= 8"
  58. ]
  59. }),
  60. require('cssnano')
  61. ]
  62. }
  63. }
  64. ],
  65. fallback: ['vue-style-loader']
  66. })
  67. },
  68. {
  69. test: /\.scss$/,
  70. loader: ExtractTextPlugin.extract({
  71. use: [
  72. 'css-loader',
  73. 'sass-loader',
  74. {
  75. loader: 'postcss-loader',
  76. options: {
  77. plugins: (loader) => [
  78. require('autoprefixer')({
  79. overrideBrowserslist: [
  80. "Android 4.1",
  81. "iOS 7.1",
  82. "Chrome > 31",
  83. "ff > 31",
  84. "ie >= 8"
  85. ]
  86. }),
  87. require('cssnano')
  88. ]
  89. }
  90. }
  91. ],
  92. fallback: ['vue-style-loader']
  93. })
  94. }
  95. ]
  96. },
  97. plugins: [
  98. new ProgressPlugin(),
  99. new ExtractTextPlugin({ filename: 'css/[name].[contenthash:7].css', allChunks: true }),
  100. new webpack.optimize.CommonsChunkPlugin({ name: 'common', filename: 'js/[name].[hash:7].js' }),
  101. new webpack.optimize.OccurrenceOrderPlugin(),
  102. new OptimizeCssAssetsPlugin({
  103. assetNameRegExp: /\.css$/g,
  104. cssProcessor: require('cssnano'),
  105. cssProcessorOptions: { discardComments: { removeAll: true } },
  106. canPrint: true
  107. }),
  108. new UglifyJSPlugin({
  109. parallel: true,
  110. sourceMap: true,
  111. uglifyOptions: {
  112. compress: {
  113. warnings: false,
  114. drop_debugger: true,
  115. drop_console: true,
  116. pure_funcs: ['console.log']// remove console
  117. },
  118. comments: function (n, c) {
  119. /*! IMPORTANT: Please preserve 3rd-party library license info, inspired from @allex/amd-build-worker/config/jsplumb.js */
  120. var text = c.value, type = c.type
  121. if (type === 'comment2') {
  122. return /^!|@preserve|@license|@cc_on|MIT/i.test(text)
  123. }
  124. }
  125. }
  126. }),
  127. new CopyWebpackPlugin([
  128. {
  129. from: resolve('src/combo'),
  130. to: resolve('dist/combo')
  131. },
  132. {
  133. from: resolve('src/lib'),
  134. to: resolve('dist/lib')
  135. },
  136. {
  137. from: resolve('src/images'),
  138. to: resolve('dist/images')
  139. },
  140. ]),
  141. ]
  142. })
  143. module.exports = config