webpack.base.conf.js 2.6 KB

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