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

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