Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-18 19:22:23
  4. */
  5. const path = require('path')
  6. const webpack = require('webpack')
  7. const packageInfo = require('./package.json')
  8. const CopyWebpackPlugin = require('copy-webpack-plugin')
  9. const cesiumBuild = 'node_modules/cesium/Build/Cesium'
  10. let cesiumCopyPlugin = [
  11. new CopyWebpackPlugin([
  12. { from: path.join(cesiumBuild, 'Assets'), to: 'resources/Assets' },
  13. { from: path.join(cesiumBuild, 'Workers'), to: 'resources/Workers' },
  14. { from: path.join(cesiumBuild, 'ThirdParty'), to: 'resources/ThirdParty' }
  15. ])
  16. ]
  17. function resolve(dir) {
  18. return path.join(__dirname, '.', dir)
  19. }
  20. function getTime() {
  21. let now = new Date()
  22. let m = now.getMonth() + 1
  23. m = m < 10 ? '0' + m : m
  24. let d = now.getDate()
  25. d = d < 10 ? '0' + d : d
  26. return `${now.getFullYear()}-${m}-${d}`
  27. }
  28. module.exports = env => {
  29. const IS_PROD = (env && env.production) || false
  30. const publicPath = IS_PROD ? '/' : '/'
  31. let plugins = [
  32. ...cesiumCopyPlugin,
  33. new webpack.DefinePlugin({
  34. CESIUM_BASE_URL: JSON.stringify('./libs/dc-sdk/resources/'),
  35. __VERSION__: JSON.stringify(packageInfo.version),
  36. __TIME__: JSON.stringify(getTime()),
  37. __AUTHOR__: JSON.stringify(packageInfo.author),
  38. __REPOSITORY__: JSON.stringify(packageInfo.repository),
  39. __HOME_PAGE__: JSON.stringify(packageInfo.homepage)
  40. })
  41. ]
  42. if (IS_PROD) {
  43. plugins.push(new webpack.NoEmitOnErrorsPlugin())
  44. }
  45. return {
  46. entry: {
  47. 'dc.base': ['base']
  48. },
  49. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  50. output: {
  51. filename: IS_PROD ? '[name].min.js' : '[name].js',
  52. path: path.resolve(__dirname, 'dist'),
  53. publicPath: publicPath,
  54. library: 'DC',
  55. libraryExport: 'default',
  56. libraryTarget: 'umd',
  57. umdNamedDefine: true
  58. },
  59. amd: {
  60. toUrlUndefined: true
  61. },
  62. node: {
  63. fs: 'empty'
  64. },
  65. module: {
  66. unknownContextCritical: false,
  67. rules: [
  68. {
  69. test: /\.js$/,
  70. exclude: /node_modules/,
  71. loader: 'babel-loader',
  72. options: {
  73. presets: ['@babel/preset-env'],
  74. plugins: ['@babel/transform-runtime'],
  75. compact: false,
  76. ignore: ['checkTree']
  77. }
  78. }
  79. ]
  80. },
  81. resolve: {
  82. extensions: ['.js', '.json', '.css'],
  83. alias: {
  84. '@': resolve('src'),
  85. base: './src/base/index.js',
  86. cesium: path.resolve(__dirname, cesiumBuild)
  87. }
  88. },
  89. plugins
  90. }
  91. }