Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

webpack.config.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 MiniCssExtractPlugin = require('mini-css-extract-plugin')
  8. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  9. const JavaScriptObfuscator = require('webpack-obfuscator')
  10. const cesiumBuild = 'node_modules/cesium/Build/Cesium'
  11. function resolve(dir) {
  12. return path.join(__dirname, '.', dir)
  13. }
  14. module.exports = env => {
  15. const IS_PROD = (env && env.production) || false
  16. const publicPath = IS_PROD ? '/' : '/'
  17. let plugins = [
  18. new MiniCssExtractPlugin({
  19. filename: IS_PROD ? '[name].min.css' : '[name].css',
  20. allChunks: true
  21. })
  22. ]
  23. if (IS_PROD) {
  24. plugins.push(new OptimizeCssAssetsPlugin())
  25. plugins.push(new webpack.NoEmitOnErrorsPlugin())
  26. plugins.push(
  27. new JavaScriptObfuscator(
  28. {
  29. rotateStringArray: true
  30. },
  31. []
  32. )
  33. )
  34. }
  35. return {
  36. entry: {
  37. 'dc.core': ['theme', 'entry']
  38. },
  39. devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
  40. output: {
  41. filename: IS_PROD ? '[name].min.js' : '[name].js',
  42. path: path.resolve(__dirname, 'dist'),
  43. publicPath: publicPath,
  44. library: 'DcCore',
  45. libraryTarget: 'umd',
  46. umdNamedDefine: true
  47. },
  48. module: {
  49. unknownContextCritical: false,
  50. rules: [
  51. {
  52. test: /\.js$/,
  53. exclude: /node_modules/,
  54. loader: 'babel-loader',
  55. options: {
  56. presets: ['@babel/preset-env'],
  57. plugins: ['@babel/transform-runtime'],
  58. compact: false,
  59. ignore: ['checkTree']
  60. }
  61. },
  62. {
  63. test: /\.css$/,
  64. use: [
  65. MiniCssExtractPlugin.loader,
  66. {
  67. loader: 'css-loader'
  68. },
  69. {
  70. loader: 'sass-loader'
  71. }
  72. ]
  73. },
  74. {
  75. test: /\.scss$/,
  76. use: [
  77. MiniCssExtractPlugin.loader,
  78. {
  79. loader: 'css-loader'
  80. },
  81. {
  82. loader: 'sass-loader'
  83. }
  84. ]
  85. },
  86. {
  87. test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
  88. loader: 'url-loader',
  89. options: {
  90. limit: 20000
  91. }
  92. },
  93. {
  94. test: /\.glsl$/,
  95. loader: 'webpack-glsl-loader'
  96. }
  97. ]
  98. },
  99. resolve: {
  100. extensions: ['.js', '.json', '.css'],
  101. alias: {
  102. '@': resolve('src'),
  103. entry: './src/core/index.js',
  104. theme: './src/themes/index.js',
  105. cesium: path.resolve(__dirname, cesiumBuild)
  106. }
  107. },
  108. plugins
  109. }
  110. }