webpack.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. use: ['babel-loader'],
  25. exclude: /node_modules/
  26. },
  27. {
  28. test: /\.css$/,
  29. use: ['style-loader', 'css-loader', 'postcss-loader']
  30. },
  31. {
  32. test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
  33. use: [{
  34. loader: 'url-loader',
  35. options: {
  36. limit: 10000
  37. }
  38. }]
  39. }
  40. ]
  41. },
  42. plugins: [
  43. new webpack.optimize.CommonsChunkPlugin({
  44. names: ['vendor', 'manifest']
  45. }),
  46. new HtmlWebpackPlugin({
  47. template: 'src/index.html'
  48. })
  49. ],
  50. resolve: {
  51. alias: {
  52. '~': resolve(__dirname, 'src')
  53. }
  54. },
  55. devServer: {
  56. host: '127.0.0.1',
  57. port: 8010,
  58. proxy: {
  59. '/api/': {
  60. target: 'http://127.0.0.1:8080',
  61. changeOrigin: true,
  62. pathRewrite: {
  63. '^/api': ''
  64. }
  65. }
  66. },
  67. historyApiFallback: {
  68. index: url.parse(options.dev ? '/assets/' : publicPath).pathname
  69. }
  70. },
  71. devtool: options.dev ? '#eval-source-map' : '#source-map'
  72. })