webpack.base.conf.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const VueLoaderPlugin = require('vue-loader/lib/plugin')
  6. const vueLoaderConfig = require('./vue-loader.conf')
  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. plugins: [
  33. new VueLoaderPlugin()
  34. ],
  35. resolve: {
  36. extensions: ['.js', '.vue', '.json'],
  37. alias: {
  38. 'vue$': 'vue/dist/vue.esm.js',
  39. '@': resolve('src'),
  40. }
  41. },
  42. module: {
  43. rules: [
  44. //...(config.dev.useEslint ? [createLintingRule()] : []),
  45. {
  46. test: /\.html$/,
  47. use: 'html-loader'
  48. },
  49. {
  50. test: /\.vue$/,
  51. loader: 'vue-loader',
  52. options: vueLoaderConfig
  53. },
  54. {
  55. test: /\.js$/,
  56. loader: 'babel-loader',
  57. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  58. },
  59. {
  60. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  61. loader: 'url-loader',
  62. options: {
  63. limit: 10000,
  64. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  65. }
  66. },
  67. {
  68. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  69. loader: 'url-loader',
  70. options: {
  71. limit: 10000,
  72. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  73. }
  74. },
  75. {
  76. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  77. loader: 'url-loader',
  78. options: {
  79. limit: 10000,
  80. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  81. }
  82. },
  83. {
  84. test: /\.css$/i,
  85. use: ["style-loader", "css-loader"],
  86. },
  87. {
  88. test: /\.less$/,
  89. use: [
  90. // ...其他 loader 配置
  91. {
  92. loader: 'less-loader',
  93. options: {
  94. // 若 less-loader 版本小于 6.0,请移除 lessOptions 这一级,直接配置选项。
  95. modifyVars: {
  96. // 直接覆盖变量
  97. 'text-color': '#fff',
  98. "nav-bar-title-text-color":'#fff'
  99. // 或者可以通过 less 文件覆盖(文件路径为绝对路径)
  100. //hack: `true; @import "your-less-file-path.less";`,
  101. },
  102. },
  103. },
  104. ],
  105. },
  106. {
  107. test: /\.sass$/,
  108. // loader: 'style-loader!css-loader!sass-loader',
  109. //loader 的解析从后向前解析
  110. use: [ 'vue-style-loader', 'css-loader', 'sass-loader' ]
  111. },
  112. {
  113. test: / \.scss$ / ,
  114. loaders: [ 'style' , 'css' , 'sass' ]
  115. }
  116. ]
  117. },
  118. node: {
  119. // prevent webpack from injecting useless setImmediate polyfill because Vue
  120. // source contains it (although only uses it if it's native).
  121. setImmediate: false,
  122. // prevent webpack from injecting mocks to Node native modules
  123. // that does not make sense for the client
  124. dgram: 'empty',
  125. fs: 'empty',
  126. net: 'empty',
  127. tls: 'empty',
  128. child_process: 'empty'
  129. }
  130. }