webpack.config.base.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict'
  2. const HtmlWebpackPlugin = require('html-webpack-plugin')
  3. const CopyWebpackPlugin = require('copy-webpack-plugin')
  4. const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
  5. const { VueLoaderPlugin } = require('vue-loader')
  6. const utils = require('./utils')
  7. module.exports = {
  8. resolve: {
  9. extensions: ['.js', '.vue', '.json'],
  10. alias: {
  11. 'vue': 'vue/dist/vue.js',
  12. 'assets': utils.resolve('assets'),
  13. 'pages': utils.resolve('src/pages'),
  14. 'static': utils.resolve('static'),
  15. 'components': utils.resolve('src/components'),
  16. 'api': utils.resolve('src/api')
  17. }
  18. },
  19. module: {
  20. rules: [
  21. {
  22. test: /\.(js|vue)$/,
  23. use: 'eslint-loader',
  24. enforce: 'pre'
  25. }, {
  26. test: /\.vue$/,
  27. use: 'vue-loader'
  28. }, {
  29. test: /\.js$/,
  30. use: {
  31. loader: 'babel-loader',
  32. }
  33. }, {
  34. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  35. use: {
  36. loader: 'url-loader',
  37. options: {
  38. limit: 10000,
  39. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  40. }
  41. }
  42. }, {
  43. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  44. use: {
  45. loader: 'url-loader',
  46. options: {
  47. limit: 10000,
  48. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  49. }
  50. }
  51. }, {
  52. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  53. use: {
  54. loader: 'url-loader',
  55. options: {
  56. limit: 10000,
  57. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  58. }
  59. }
  60. }
  61. ]
  62. },
  63. plugins: [
  64. new HtmlWebpackPlugin({
  65. filename: 'index.html',
  66. template: 'index.html',
  67. inject: true,
  68. alwaysWriteToDisk: true
  69. }),
  70. new HtmlWebpackHarddiskPlugin(),
  71. new VueLoaderPlugin(),
  72. new CopyWebpackPlugin([{
  73. from: utils.resolve('static/img'),
  74. to: utils.resolve('dist/static/img'),
  75. toType: 'dir'
  76. }])
  77. ]
  78. }