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

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