webpack.config.base.js 1.9 KB

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