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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-18 18:22:23
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-06-17 13:29:50
  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. 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. module.exports = env => {
  28. const IS_PROD = (env && env.production) || false
  29. const publicPath = IS_PROD ? '/' : '/'
  30. let plugins = [
  31. ...cesiumCopyPlugin,
  32. new MiniCssExtractPlugin({
  33. filename: IS_PROD ? '[name].min.css' : '[name].css',
  34. allChunks: true
  35. }),
  36. new webpack.DefinePlugin({
  37. CESIUM_BASE_URL: JSON.stringify('./libs/dc-sdk/resources/')
  38. })
  39. ]
  40. if (IS_PROD) {
  41. plugins.push(new OptimizeCssAssetsPlugin())
  42. plugins.push(new webpack.NoEmitOnErrorsPlugin())
  43. }
  44. return {
  45. entry: {
  46. 'dc.base': ['base'],
  47. 'dc.core': ['entry', 'theme']
  48. },
  49. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  50. output: {
  51. filename: IS_PROD ? '[name].min.js' : '[name].js',
  52. path: path.resolve(__dirname, 'dist'),
  53. publicPath: publicPath,
  54. sourcePrefix: ''
  55. },
  56. amd: {
  57. toUrlUndefined: true
  58. },
  59. node: {
  60. fs: 'empty'
  61. },
  62. module: {
  63. unknownContextCritical: false,
  64. rules: [
  65. {
  66. test: /\.js$/,
  67. exclude: /node_modules/,
  68. loader: 'babel-loader',
  69. options: {
  70. presets: ['@babel/preset-env'],
  71. plugins: ['@babel/transform-runtime'],
  72. compact: false,
  73. ignore: ['checkTree']
  74. }
  75. },
  76. {
  77. test: /\.css$/,
  78. use: [
  79. MiniCssExtractPlugin.loader,
  80. {
  81. loader: 'css-loader'
  82. },
  83. {
  84. loader: 'sass-loader'
  85. }
  86. ]
  87. },
  88. {
  89. test: /\.scss$/,
  90. use: [
  91. MiniCssExtractPlugin.loader,
  92. {
  93. loader: 'css-loader'
  94. },
  95. {
  96. loader: 'sass-loader'
  97. }
  98. ]
  99. },
  100. {
  101. test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
  102. loader: 'url-loader',
  103. options: {
  104. limit: 20000
  105. }
  106. },
  107. {
  108. test: /\.glsl$/,
  109. loader: 'webpack-glsl-loader'
  110. }
  111. ]
  112. },
  113. resolve: {
  114. extensions: ['.js', '.json', '.css'],
  115. alias: {
  116. '@': resolve('src'),
  117. base: './src/base/index.js',
  118. entry: './src/core/index.js',
  119. theme: './src/themes/index.js',
  120. cesium: path.resolve(__dirname, cesiumBuild)
  121. }
  122. },
  123. plugins
  124. }
  125. }