1
0

webpack.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const path = require('path')
  2. var webpack = require('webpack')
  3. var HtmlWebpackPlugin = require('html-webpack-plugin')
  4. var url = require('url')
  5. var publicPath = ''
  6. module.exports = (options = {}) => ({
  7. entry: {
  8. vendor: './src/vendor',
  9. index: './src/main.js'
  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. use: ['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. ],
  75. devServer: {
  76. host: '127.0.0.1',
  77. port: 8010,
  78. proxy: {
  79. '/api/': {
  80. target: 'http://127.0.0.1:8080',
  81. changeOrigin: true,
  82. pathRewrite: {
  83. '^/api': ''
  84. }
  85. }
  86. },
  87. historyApiFallback: {
  88. index: url.parse(options.dev ? '/assets/' : publicPath).pathname
  89. }
  90. }//,
  91. //devtool: options.dev ? '#eval-source-map' : '#source-map'
  92. })