webpack.base.conf.js 2.5 KB

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