You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack.base.conf.js 2.3KB

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