Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

webpack.conf.js 3.6KB

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