webpack.base.conf.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 cesiumSource = '../node_modules/cesium/Source' //定义 Cesium 源码路径
  7. const cesiumWorkers = path.join(cesiumSource,'Workers');
  8. function resolve (dir) {
  9. return path.join(__dirname, '..', dir)
  10. }
  11. module.exports = {
  12. context: path.resolve(__dirname, '../'),
  13. entry: {
  14. app: './src/main.js'
  15. },
  16. output: {
  17. path: config.build.assetsRoot,
  18. filename: '[name].js',
  19. publicPath: process.env.NODE_ENV === 'production'
  20. ? config.build.assetsPublicPath
  21. : config.dev.assetsPublicPath,
  22. sourcePrefix: ' ' //让webpack正确处理多行字符串
  23. },
  24. resolve: {
  25. extensions: ['.js', '.vue', '.json'],
  26. alias: {
  27. 'vue$': 'vue/dist/vue.esm.js',
  28. '@': resolve('src'),
  29. 'static': resolve('static'),
  30. cesium: path.resolve(__dirname, cesiumSource) //设置cesium别名
  31. }
  32. },
  33. module: {
  34. rules: [
  35. {
  36. test: /\.vue$/,
  37. loader: 'vue-loader',
  38. options: vueLoaderConfig
  39. },
  40. {
  41. test: /\.js$/,
  42. loader: 'babel-loader',
  43. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  44. },
  45. {
  46. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  47. loader: 'url-loader',
  48. options: {
  49. limit: 10000,
  50. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  51. }
  52. },
  53. {
  54. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  55. loader: 'url-loader',
  56. options: {
  57. limit: 10000,
  58. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  59. }
  60. },
  61. {
  62. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  63. loader: 'url-loader',
  64. options: {
  65. limit: 10000,
  66. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  67. }
  68. }
  69. ],
  70. unknownContextCritical: false,//阻止依赖警告
  71. },
  72. node: {
  73. // prevent webpack from injecting useless setImmediate polyfill because Vue
  74. // source contains it (although only uses it if it's native).
  75. setImmediate: false,
  76. // prevent webpack from injecting mocks to Node native modules
  77. // that does not make sense for the client
  78. dgram: 'empty',
  79. fs: 'empty',
  80. net: 'empty',
  81. tls: 'empty',
  82. child_process: 'empty'
  83. }
  84. }