webpack.config.js 2.1 KB

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