webpack.base.conf.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. const createLintingRule = () => ({
  10. // test: /\.(js|vue)$/,
  11. // loader: 'eslint-loader',
  12. // enforce: 'pre',
  13. // include: [resolve('src'), resolve('test')],
  14. // options: {
  15. // formatter: require('eslint-friendly-formatter'),
  16. // emitWarning: !config.dev.showEslintErrorsInOverlay
  17. // }
  18. })
  19. module.exports = {
  20. context: path.resolve(__dirname, '../'),
  21. entry: {
  22. app: './src/main.js'
  23. },
  24. output: {
  25. path: config.build.assetsRoot,
  26. filename: '[name].js',
  27. publicPath: process.env.NODE_ENV === 'production'
  28. ? config.build.assetsPublicPath
  29. : config.dev.assetsPublicPath
  30. },
  31. resolve: {
  32. extensions: ['.js', '.vue', '.json'],
  33. alias: {
  34. 'vue$': 'vue/dist/vue.esm.js',
  35. '@': resolve('src'),
  36. 'pkgs': resolve('src/packages'),
  37. 'assets': resolve('src/assets'),
  38. }
  39. },
  40. module: {
  41. rules: [
  42. // ...(config.dev.useEslint ? [createLintingRule()] : []),
  43. {
  44. test: /\.vue$/,
  45. loader: 'vue-loader',
  46. options: vueLoaderConfig
  47. },
  48. {
  49. test: /\.js$/,
  50. loader: 'babel-loader',
  51. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  52. },
  53. {
  54. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  55. loader: 'url-loader',
  56. options: {
  57. limit: 10000,
  58. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  59. }
  60. },
  61. {
  62. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  63. loader: 'url-loader',
  64. options: {
  65. limit: 10000,
  66. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  67. }
  68. },
  69. {
  70. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  71. loader: 'url-loader',
  72. options: {
  73. limit: 10000,
  74. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  75. }
  76. }
  77. ]
  78. },
  79. node: {
  80. // prevent webpack from injecting useless setImmediate polyfill because Vue
  81. // source contains it (although only uses it if it's native).
  82. setImmediate: false,
  83. // prevent webpack from injecting mocks to Node native modules
  84. // that does not make sense for the client
  85. dgram: 'empty',
  86. fs: 'empty',
  87. net: 'empty',
  88. tls: 'empty',
  89. child_process: 'empty'
  90. }
  91. }