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.config.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-18 18:22:23
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-01-18 19:10:53
  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: 'Workers' }]),
  16. new CopywebpackPlugin([{ from: path.join(cesiumBuild, 'Assets'), to: 'Assets' }]),
  17. new CopywebpackPlugin([{ from: path.join(cesiumBuild, 'Widgets'), to: 'Widgets' }]),
  18. new CopywebpackPlugin([{ from: path.join(cesiumBuild, 'ThirdParty'), to: '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/')
  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. 'dc.plugins': ['plugins']
  44. },
  45. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  46. output: {
  47. filename: IS_PROD ? '[name].min.js' : '[name].js',
  48. path: path.resolve(__dirname, 'dist/dc'),
  49. publicPath: publicPath,
  50. sourcePrefix: ''
  51. },
  52. amd: {
  53. toUrlUndefinded: true
  54. },
  55. node: {
  56. fs: 'empty'
  57. },
  58. module: {
  59. unknownContextCritical: false,
  60. rules: [
  61. {
  62. test: /\.js$/,
  63. enforce: 'pre',
  64. include: path.resolve(__dirname, cesiumSource),
  65. use: [
  66. {
  67. loader: 'strip-pragma-loader',
  68. options: {
  69. pragmas: {
  70. debug: false
  71. }
  72. }
  73. }
  74. ]
  75. },
  76. {
  77. test: /\.js$/,
  78. exclude: /node_modules/,
  79. loader: 'babel-loader',
  80. query: {
  81. presets: ['@babel/preset-env'],
  82. compact: false,
  83. ignore: ['checkTree']
  84. }
  85. },
  86. {
  87. test: /\.css$/,
  88. use: [
  89. MiniCssExtractPlugin.loader,
  90. {
  91. loader: 'css-loader'
  92. },
  93. {
  94. loader: 'sass-loader'
  95. }
  96. ]
  97. },
  98. {
  99. test: /\.scss$/,
  100. use: [
  101. MiniCssExtractPlugin.loader,
  102. {
  103. loader: 'css-loader'
  104. },
  105. {
  106. loader: 'sass-loader'
  107. }
  108. ]
  109. },
  110. {
  111. test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
  112. loader: 'url-loader',
  113. options: {
  114. limit: 20000
  115. }
  116. }
  117. ]
  118. },
  119. resolve: {
  120. extensions: ['.js', '.json', '.css'],
  121. alias: {
  122. '@': resolve('src'),
  123. entry: './src/core/DC.js',
  124. theme: './src/themes/index.js',
  125. plugins: './src/plugins/DC.Pulgins.js',
  126. thirdpart: './src/thirdpart/index.js',
  127. cesium: path.resolve(__dirname, cesiumSource)
  128. }
  129. },
  130. plugins
  131. }
  132. }