Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

webpack.base.conf.js 2.7KB

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