webpack.base.conf.js 3.5 KB

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