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