1.带cesium

  1. /*
  2. * @Author: wangchaoxu
  3. * @Date: 2020-05-12 17:17:38
  4. * @LastEditors: wangchaoxu
  5. * @LastEditTime: 2020-10-09 08:54:44
  6. * @Description: vue配置文件
  7. */
  8. 'use strict';
  9. const path = require('path');
  10. const cesiumSource = './node_modules/cesium/Source'; //cesium的目录
  11. const webpack = require('webpack');
  12. const CopywebpackPlugin = require('copy-webpack-plugin'); //复制文件
  13. const CompressionWebpackPlugin = require('compression-webpack-plugin'); //gzip压缩
  14. const TerserPlugin = require('terser-webpack-plugin');
  15. const productionGzipExtensions = ['js', 'css', 'json', 'txt'];
  16. const env = process.env.NODE_ENV;
  17. let resolve = dir => {
  18. return path.resolve(__dirname, dir);
  19. };
  20. console.log(`==========当前运行环境:${env}=========`);
  21. module.exports = {
  22. publicPath: env === 'production' ? './' : './',
  23. productionSourceMap: env === 'development',
  24. devServer: {
  25. host: '0.0.0.0',
  26. open: true,
  27. hot: true,
  28. port: 3000,
  29. proxy: {
  30. '/baiduApi': {
  31. target: 'https://restapi.amap.com', //访问地址
  32. changeOrigin: true,
  33. secure: false, //只有代理https 地址需要次选项
  34. logLevel: 'debug', //可以打印出代理后请求的
  35. pathRewrite: {
  36. '^/baiduApi': ''
  37. }
  38. },
  39. '/api': {
  40. target: 'http://localhost:2510/', //访问地址
  41. changeOrigin: true,
  42. secure: false, //只有代理https 地址需要次选项
  43. logLevel: 'debug' //可以打印出代理后请求的
  44. }
  45. }
  46. },
  47. pluginOptions: {
  48. 'style-resources-loader': {
  49. preProcessor: 'less',
  50. patterns: [path.resolve(__dirname, './src/assets/style/mixin.less'), path.resolve(__dirname, './src/assets/style/variable.less')]
  51. }
  52. },
  53. configureWebpack: config => {
  54. if (env === 'production') {
  55. config.plugins.push(
  56. new CompressionWebpackPlugin({
  57. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  58. threshold: 10240, // 对超过10k的数据压缩
  59. deleteOriginalAssets: false // 不删除源文件
  60. }),
  61. new TerserPlugin({
  62. extractComments: true,
  63. cache: true,
  64. parallel: true,
  65. sourceMap: true, // Must be set to true if using source-maps in production
  66. terserOptions: {
  67. extractComments: 'all',
  68. compress: {
  69. drop_console: true
  70. }
  71. }
  72. })
  73. );
  74. }
  75. },
  76. chainWebpack: config => {
  77. config.resolve.extensions.add('.js').add('.vue');
  78. config.resolve.alias
  79. .set('@', resolve('src'))
  80. .set('@assets', resolve('src/assets'))
  81. .set('@images', resolve('src/images'))
  82. .set('@cmp', resolve('src/components'))
  83. .set('@views', resolve('src/views'));
  84. config.plugin('copy').use(CopywebpackPlugin, [
  85. [
  86. { from: path.join(cesiumSource, 'Workers'), to: 'resources/Workers' },
  87. { from: path.join(cesiumSource, 'Assets'), to: 'resources/Assets' },
  88. { from: path.join(cesiumSource, 'Widgets'), to: 'resources/Widgets' },
  89. {
  90. from: path.join(cesiumSource, 'ThirdParty'),
  91. to: 'resources/ThirdParty'
  92. }
  93. ]
  94. ]);
  95. config.plugin('html').tap(args => {
  96. args[0].title = '农业气象服务平台';
  97. return args;
  98. });
  99. config.plugin('define').use(webpack.DefinePlugin, [{ CESIUM_BASE_URL: JSON.stringify('./resources/') }]);
  100. if (env === 'production') {
  101. // 移除 prefetch 插件
  102. config.plugins.delete('prefetch');
  103. // 移除 preload 插件
  104. config.plugins.delete('preload');
  105. }
  106. }
  107. };

2.不带cesium

3.nuxt配置