webpack.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const resolve = require('path').resolve
  2. const webpack = require('webpack')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const url = require('url')
  5. const publicPath = ''
  6. module.exports = (options = {}) => ({
  7. entry: {
  8. vendor: './src/vendor',
  9. index: './src/main.js'
  10. },
  11. output: {
  12. 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. module: {
  18. rules: [{
  19. test: /\.vue$/,
  20. use: ['vue-loader']
  21. },
  22. {
  23. test: /\.js$/,
  24. loader: 'babel-loader',
  25. options: {
  26. presets: ['es2015']
  27. },
  28. include: [resolve('src')]
  29. },
  30. {
  31. test: /\.css$/,
  32. use: ['style-loader', 'css-loader', 'postcss-loader']
  33. },
  34. {
  35. test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
  36. use: [{
  37. loader: 'url-loader',
  38. options: {
  39. limit: 10000
  40. }
  41. }]
  42. }
  43. ]
  44. },
  45. plugins: [
  46. new webpack.optimize.CommonsChunkPlugin({
  47. names: ['vendor', 'manifest']
  48. }),
  49. new HtmlWebpackPlugin({
  50. template: 'src/index.html'
  51. })
  52. ],
  53. resolve: {
  54. alias: {
  55. '~': resolve(__dirname, 'src')
  56. },
  57. extensions: ['.js', '.vue', '.json', '.css']
  58. },
  59. devServer: {
  60. host: '127.0.0.1',
  61. port: 8010,
  62. proxy: {
  63. '/api/': {
  64. target: 'http://127.0.0.1:8080',
  65. changeOrigin: true,
  66. pathRewrite: {
  67. '^/api': ''
  68. }
  69. }
  70. },
  71. historyApiFallback: {
  72. index: url.parse(options.dev ? '/assets/' : publicPath).pathname
  73. }
  74. },
  75. devtool: options.dev ? '#eval-source-map' : '#source-map'
  76. })