webpack.base.conf.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const vueLoaderConfig = require('./vue-loader.conf')
  6. function resolve(dir) {
  7. return path.join(__dirname, '..', dir)
  8. }
  9. module.exports = {
  10. // devServer: {
  11. // headers: {
  12. // "Cross-Origin-Opener-Policy": "same-origin", // 保护你的源站点免受攻击
  13. // "Cross-Origin-Embedder-Policy": "require-corp", // 保护受害者免受你的源站点的影响
  14. // },
  15. // },
  16. context: path.resolve(__dirname, '../'),
  17. entry: {
  18. app: './src/main.js'
  19. },
  20. output: {
  21. path: config.build.assetsRoot,
  22. filename: '[name].js',
  23. publicPath: process.env.NODE_ENV === 'production'
  24. ? config.build.assetsPublicPath
  25. : config.dev.assetsPublicPath
  26. },
  27. resolve: {
  28. extensions: ['.js', '.vue', '.json'],
  29. alias: {
  30. 'vue$': 'vue/dist/vue.esm.js',
  31. '@': resolve('src'),
  32. }
  33. },
  34. module: {
  35. rules: [
  36. {
  37. test: /\.vue$/,
  38. loader: 'vue-loader',
  39. options: vueLoaderConfig
  40. },
  41. {
  42. test: /\.js$/,
  43. loader: 'babel-loader',
  44. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  45. },
  46. {
  47. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  48. loader: 'url-loader',
  49. options: {
  50. limit: 10000,
  51. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  52. }
  53. },
  54. {
  55. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  56. loader: 'url-loader',
  57. options: {
  58. limit: 10000,
  59. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  60. }
  61. },
  62. {
  63. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  64. loader: 'url-loader',
  65. options: {
  66. limit: 10000,
  67. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  68. }
  69. }
  70. ]
  71. },
  72. node: {
  73. // prevent webpack from injecting useless setImmediate polyfill because Vue
  74. // source contains it (although only uses it if it's native).
  75. setImmediate: false,
  76. // prevent webpack from injecting mocks to Node native modules
  77. // that does not make sense for the client
  78. dgram: 'empty',
  79. fs: 'empty',
  80. net: 'empty',
  81. tls: 'empty',
  82. child_process: 'empty'
  83. }
  84. }