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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-18 18:22:23
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-01-31 15:49:20
  6. */
  7. const path = require('path')
  8. const webpack = require('webpack')
  9. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  10. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  11. const CopywebpackPlugin = require('copy-webpack-plugin')
  12. const cesiumBuild = './libs/cesium/Build/Cesium'
  13. const cesiumSource = './libs/cesium/Source'
  14. let cesiumCopyPlugin = [
  15. new CopywebpackPlugin([{ from: path.join(cesiumBuild, 'Workers'), to: 'resources/Workers' }]),
  16. new CopywebpackPlugin([{ from: path.join(cesiumBuild, 'Assets'), to: 'resources/Assets' }]),
  17. new CopywebpackPlugin([{ from: path.join(cesiumBuild, 'Widgets'), to: 'resources/Widgets' }]),
  18. new CopywebpackPlugin([{ from: path.join(cesiumBuild, 'ThirdParty'), to: 'resources/ThirdParty' }])
  19. ]
  20. function resolve(dir) {
  21. return path.join(__dirname, '.', dir)
  22. }
  23. module.exports = env => {
  24. const IS_PROD = (env && env.production) || false
  25. const publicPath = IS_PROD ? '/' : '/'
  26. let plugins = [
  27. ...cesiumCopyPlugin,
  28. new MiniCssExtractPlugin({
  29. filename: IS_PROD ? '[name].min.css' : '[name].css',
  30. allChunks: true
  31. }),
  32. new webpack.DefinePlugin({
  33. CESIUM_BASE_URL: JSON.stringify('./libs/dc-sdk/resources/')
  34. })
  35. ]
  36. if (IS_PROD) {
  37. plugins.push(new OptimizeCssAssetsPlugin())
  38. plugins.push(new webpack.NoEmitOnErrorsPlugin())
  39. }
  40. return {
  41. entry: {
  42. 'dc.core': ['entry', 'thirdpart', 'theme']
  43. },
  44. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  45. output: {
  46. filename: IS_PROD ? '[name].min.js' : '[name].js',
  47. path: path.resolve(__dirname, 'dist/dc-sdk'),
  48. publicPath: publicPath,
  49. sourcePrefix: ''
  50. },
  51. amd: {
  52. toUrlUndefinded: true
  53. },
  54. node: {
  55. fs: 'empty'
  56. },
  57. module: {
  58. unknownContextCritical: false,
  59. rules: [
  60. {
  61. test: /\.js$/,
  62. enforce: 'pre',
  63. include: path.resolve(__dirname, cesiumSource),
  64. use: [
  65. {
  66. loader: 'strip-pragma-loader',
  67. options: {
  68. pragmas: {
  69. debug: false
  70. }
  71. }
  72. }
  73. ]
  74. },
  75. {
  76. test: /\.js$/,
  77. exclude: /node_modules/,
  78. loader: 'babel-loader',
  79. query: {
  80. presets: ['@babel/preset-env'],
  81. compact: false,
  82. ignore: ['checkTree']
  83. }
  84. },
  85. {
  86. test: /\.css$/,
  87. use: [
  88. MiniCssExtractPlugin.loader,
  89. {
  90. loader: 'css-loader'
  91. },
  92. {
  93. loader: 'sass-loader'
  94. }
  95. ]
  96. },
  97. {
  98. test: /\.scss$/,
  99. use: [
  100. MiniCssExtractPlugin.loader,
  101. {
  102. loader: 'css-loader'
  103. },
  104. {
  105. loader: 'sass-loader'
  106. }
  107. ]
  108. },
  109. {
  110. test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
  111. loader: 'url-loader',
  112. options: {
  113. limit: 20000
  114. }
  115. }
  116. ]
  117. },
  118. resolve: {
  119. extensions: ['.js', '.json', '.css'],
  120. alias: {
  121. '@': resolve('src'),
  122. entry: './src/core/DC.js',
  123. theme: './src/themes/index.js',
  124. thirdpart: './src/thirdpart/index.js',
  125. cesium: path.resolve(__dirname, cesiumSource)
  126. }
  127. },
  128. plugins
  129. }
  130. }