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.6KB

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