選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

webpack.sdk.conf.js 2.3KB

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