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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-18 18:22:23
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-07-27 10:39:55
  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 JavaScriptObfuscator = require('webpack-obfuscator')
  13. const cesiumBuild = 'node_modules/cesium/Build/Cesium'
  14. let cesiumCopyPlugin = [
  15. new CopywebpackPlugin([
  16. { from: path.join(cesiumBuild, 'Assets'), to: 'resources/Assets' }
  17. ]),
  18. new CopywebpackPlugin([
  19. { from: path.join(cesiumBuild, 'Workers'), to: 'resources/Workers' }
  20. ]),
  21. new CopywebpackPlugin([
  22. { from: path.join(cesiumBuild, 'ThirdParty'), to: 'resources/ThirdParty' }
  23. ])
  24. ]
  25. function resolve(dir) {
  26. return path.join(__dirname, '.', dir)
  27. }
  28. module.exports = env => {
  29. const IS_PROD = (env && env.production) || false
  30. const publicPath = IS_PROD ? '/' : '/'
  31. let plugins = [
  32. ...cesiumCopyPlugin,
  33. new MiniCssExtractPlugin({
  34. filename: IS_PROD ? '[name].min.css' : '[name].css',
  35. allChunks: true
  36. }),
  37. new webpack.DefinePlugin({
  38. CESIUM_BASE_URL: JSON.stringify('./libs/dc-sdk/resources/')
  39. })
  40. ]
  41. if (IS_PROD) {
  42. plugins.push(new OptimizeCssAssetsPlugin())
  43. plugins.push(new webpack.NoEmitOnErrorsPlugin())
  44. plugins.push(
  45. new JavaScriptObfuscator(
  46. {
  47. rotateStringArray: true
  48. },
  49. ['dc.base.min.js']
  50. )
  51. )
  52. }
  53. return {
  54. entry: {
  55. 'dc.base': ['base'],
  56. 'dc.core': ['entry', 'theme']
  57. },
  58. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  59. output: {
  60. filename: IS_PROD ? '[name].min.js' : '[name].js',
  61. path: path.resolve(__dirname, 'dist'),
  62. publicPath: publicPath,
  63. sourcePrefix: ''
  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. 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. test: /\.glsl$/,
  118. loader: 'webpack-glsl-loader'
  119. }
  120. ]
  121. },
  122. resolve: {
  123. extensions: ['.js', '.json', '.css'],
  124. alias: {
  125. '@': resolve('src'),
  126. base: './src/base/index.js',
  127. entry: './src/core/index.js',
  128. theme: './src/themes/index.js',
  129. cesium: path.resolve(__dirname, cesiumBuild)
  130. }
  131. },
  132. plugins
  133. }
  134. }