webpack.config.prod.js 4.3 KB

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