Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

webpack.config.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-01-18 19:22:23
  4. */
  5. const path = require('path')
  6. const webpack = require('webpack')
  7. const packageInfo = require('./package.json')
  8. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  9. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  10. const CopyWebpackPlugin = require('copy-webpack-plugin')
  11. const JavaScriptObfuscator = require('webpack-obfuscator')
  12. const cesiumBuild = 'node_modules/cesium/Build/Cesium'
  13. let cesiumCopyPlugin = [
  14. new CopyWebpackPlugin([
  15. { from: path.join(cesiumBuild, 'Assets'), to: 'resources/Assets' }
  16. ]),
  17. new CopyWebpackPlugin([
  18. { from: path.join(cesiumBuild, 'Workers'), to: 'resources/Workers' }
  19. ]),
  20. new CopyWebpackPlugin([
  21. { from: path.join(cesiumBuild, 'ThirdParty'), to: 'resources/ThirdParty' }
  22. ])
  23. ]
  24. function resolve(dir) {
  25. return path.join(__dirname, '.', dir)
  26. }
  27. function getTime() {
  28. let now = new Date()
  29. let m = now.getMonth() + 1
  30. m = m < 10 ? '0' + m : m
  31. let d = now.getDate()
  32. d = d < 10 ? '0' + d : d
  33. let h = now.getHours()
  34. h = h < 10 ? '0' + h : h
  35. let min = now.getMinutes()
  36. min = min < 10 ? '0' + min : min
  37. let s = now.getSeconds()
  38. s = s < 10 ? '0' + s : s
  39. return `${now.getFullYear()}-${m}-${d} ${h}:${min}:${s}`
  40. }
  41. module.exports = env => {
  42. const IS_PROD = (env && env.production) || false
  43. const publicPath = IS_PROD ? '/' : '/'
  44. let plugins = [
  45. ...cesiumCopyPlugin,
  46. new MiniCssExtractPlugin({
  47. filename: IS_PROD ? '[name].min.css' : '[name].css',
  48. allChunks: true
  49. }),
  50. new webpack.DefinePlugin({
  51. CESIUM_BASE_URL: JSON.stringify('./libs/dc-sdk/resources/'),
  52. 'build.version': JSON.stringify(packageInfo.version),
  53. 'build.time': JSON.stringify(getTime())
  54. })
  55. ]
  56. if (IS_PROD) {
  57. plugins.push(new OptimizeCssAssetsPlugin())
  58. plugins.push(new webpack.NoEmitOnErrorsPlugin())
  59. plugins.push(
  60. new JavaScriptObfuscator(
  61. {
  62. rotateStringArray: true
  63. },
  64. ['dc.base.min.js']
  65. )
  66. )
  67. }
  68. return {
  69. entry: {
  70. 'dc.base': ['base'],
  71. 'dc.core': ['entry', 'theme']
  72. },
  73. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  74. output: {
  75. filename: IS_PROD ? '[name].min.js' : '[name].js',
  76. path: path.resolve(__dirname, 'dist'),
  77. publicPath: publicPath,
  78. sourcePrefix: ''
  79. },
  80. amd: {
  81. toUrlUndefined: true
  82. },
  83. node: {
  84. fs: 'empty'
  85. },
  86. module: {
  87. unknownContextCritical: false,
  88. rules: [
  89. {
  90. test: /\.js$/,
  91. exclude: /node_modules/,
  92. loader: 'babel-loader',
  93. options: {
  94. presets: ['@babel/preset-env'],
  95. plugins: ['@babel/transform-runtime'],
  96. compact: false,
  97. ignore: ['checkTree']
  98. }
  99. },
  100. {
  101. test: /\.css$/,
  102. use: [
  103. MiniCssExtractPlugin.loader,
  104. {
  105. loader: 'css-loader'
  106. },
  107. {
  108. loader: 'sass-loader'
  109. }
  110. ]
  111. },
  112. {
  113. test: /\.scss$/,
  114. use: [
  115. MiniCssExtractPlugin.loader,
  116. {
  117. loader: 'css-loader'
  118. },
  119. {
  120. loader: 'sass-loader'
  121. }
  122. ]
  123. },
  124. {
  125. test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
  126. loader: 'url-loader',
  127. options: {
  128. limit: 20000
  129. }
  130. },
  131. {
  132. test: /\.glsl$/,
  133. loader: 'webpack-glsl-loader'
  134. }
  135. ]
  136. },
  137. resolve: {
  138. extensions: ['.js', '.json', '.css'],
  139. alias: {
  140. '@': resolve('src'),
  141. base: './src/base/index.js',
  142. entry: './src/core/index.js',
  143. theme: './src/themes/index.js',
  144. cesium: path.resolve(__dirname, cesiumBuild)
  145. }
  146. },
  147. plugins
  148. }
  149. }