webpack.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const path = require('path')
  2. var webpack = require('webpack')
  3. var HtmlWebpackPlugin = require('html-webpack-plugin')
  4. var VueLoaderPlugin = require('vue-loader/lib/plugin')
  5. var url = require('url')
  6. var publicPath = ''
  7. module.exports = (options = {}) => ({
  8. entry: {
  9. vendor: './src/main'
  10. },
  11. output: {
  12. path: path.resolve(__dirname, 'dist'),
  13. filename: options.dev ? '[name].js' : '[name].js?[chunkhash]',
  14. chunkFilename: '[id].js?[chunkhash]',
  15. publicPath: options.dev ? '/assets/' : publicPath
  16. },
  17. resolve: {
  18. extensions: ['.js', '.vue', '.json'],
  19. alias: {
  20. 'vue$': 'vue/dist/vue.esm.js',
  21. '@': path.resolve(__dirname, 'src'),
  22. }
  23. },
  24. module: {
  25. rules: [{
  26. test: /\.vue$/,
  27. loader: 'vue-loader'
  28. }, {
  29. test: /\.js$/,
  30. use: ['babel-loader'],
  31. exclude: /node_modules/
  32. }, {
  33. test: /\.html$/,
  34. use: [{
  35. loader: 'html-loader',
  36. options: {
  37. root: path.resolve(__dirname, 'src'),
  38. attrs: ['img:src', 'link:href']
  39. }
  40. }]
  41. }, {
  42. test: /\.less$/,
  43. loader: 'style-loader!css-loader!postcss-loader!less-loader'
  44. }, {
  45. test: /\.css$/,
  46. use: ['style-loader', 'css-loader', 'postcss-loader']
  47. }, {
  48. test: /favicon\.png$/,
  49. use: [{
  50. loader: 'file-loader',
  51. options: {
  52. name: '[name].[ext]?[hash]'
  53. }
  54. }]
  55. }, {
  56. test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
  57. exclude: /favicon\.png$/,
  58. use: [{
  59. loader: 'url-loader',
  60. options: {
  61. limit: 10000
  62. }
  63. }]
  64. }]
  65. },
  66. plugins: [
  67. new webpack.optimize.CommonsChunkPlugin({
  68. names: ['vendor', 'manifest']
  69. }),
  70. new HtmlWebpackPlugin({
  71. favicon: 'src/assets/favicon.ico',
  72. template: 'src/index.html'
  73. }),
  74. new webpack.NormalModuleReplacementPlugin(/element-ui[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]zh-CN/, 'element-ui/lib/locale/lang/en'),
  75. new webpack.DefinePlugin({
  76. 'process.env': {
  77. NODE_ENV: '"production"'
  78. }
  79. }),
  80. new webpack.optimize.UglifyJsPlugin({
  81. sourceMap: false,
  82. comments: false,
  83. compress: {
  84. warnings: false
  85. }
  86. }),
  87. new VueLoaderPlugin()
  88. ],
  89. devServer: {
  90. host: '127.0.0.1',
  91. port: 8010,
  92. proxy: {
  93. '/api/': {
  94. target: 'http://127.0.0.1:8080',
  95. changeOrigin: true,
  96. pathRewrite: {
  97. '^/api': ''
  98. }
  99. }
  100. },
  101. historyApiFallback: {
  102. index: url.parse(options.dev ? '/assets/' : publicPath).pathname
  103. }
  104. }//,
  105. //devtool: options.dev ? '#eval-source-map' : '#source-map'
  106. })