webpack.base.conf.js 2.6 KB

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