webpack.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. const fs = require('fs');
  17. const webpack = require('webpack');
  18. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  19. const {
  20. BUNDLES,
  21. getPluginConfig,
  22. splitChunksName
  23. } = require('./desktop/core/src/desktop/js/webpack/configUtils');
  24. const config = {
  25. devtool: 'cheap-source-map',
  26. entry: {
  27. hue: { import: './desktop/core/src/desktop/js/hue.js' },
  28. editor: { import: './desktop/core/src/desktop/js/apps/editor/app.js', dependOn: 'hue' },
  29. notebook: { import: './desktop/core/src/desktop/js/apps/notebook/app.js', dependOn: 'hue' },
  30. tableBrowser: {
  31. import: './desktop/core/src/desktop/js/apps/tableBrowser/app.js',
  32. dependOn: 'hue'
  33. },
  34. jobBrowser: { import: './desktop/core/src/desktop/js/apps/jobBrowser/app.js', dependOn: 'hue' }
  35. },
  36. mode: 'development',
  37. module: {
  38. rules: [
  39. {
  40. test: /\.vue$/,
  41. exclude: /node_modules/,
  42. use: 'vue-loader'
  43. },
  44. {
  45. test: /\.(jsx?|tsx?)$/,
  46. exclude: /node_modules/,
  47. use: [
  48. {
  49. loader: 'babel-loader',
  50. options: {
  51. presets: ['@babel/preset-env', '@babel/preset-react']
  52. }
  53. }
  54. ]
  55. },
  56. {
  57. test: /\.(jsx?|tsx?)$/,
  58. enforce: 'pre',
  59. use: ['source-map-loader']
  60. },
  61. // Remove hardcoded references to source map files in third party mjs-files
  62. // since those files will be missing in our builds.
  63. {
  64. test: /\.mjs$/,
  65. include: /node_modules/,
  66. enforce: 'post',
  67. loader: 'strip-sourcemap-loader'
  68. },
  69. {
  70. test: /\.scss$/,
  71. exclude: /node_modules/,
  72. use: [
  73. 'style-loader',
  74. 'css-loader',
  75. {
  76. loader: 'sass-loader',
  77. options: {
  78. sassOptions: {
  79. includePaths: ['desktop/core/src/desktop/js/components/styles', 'node_modules']
  80. }
  81. }
  82. }
  83. ]
  84. },
  85. {
  86. test: /\.css$/i,
  87. use: [{ loader: 'style-loader' }, { loader: 'css-loader' }]
  88. },
  89. {
  90. test: /\.less$/i,
  91. use: [
  92. { loader: 'style-loader' },
  93. { loader: 'css-loader' },
  94. {
  95. loader: 'less-loader',
  96. options: {
  97. lessOptions: {
  98. // This is not ideal but required by antd library
  99. javascriptEnabled: true
  100. }
  101. }
  102. }
  103. ]
  104. },
  105. {
  106. test: /\.html$/,
  107. exclude: /node_modules/,
  108. use: { loader: 'html', options: { interpolater: true, removeComments: false } }
  109. }
  110. ]
  111. },
  112. optimization: {
  113. minimize: false,
  114. splitChunks: {
  115. chunks: 'all',
  116. name: splitChunksName,
  117. maxSize: 1000000,
  118. hidePathInfo: true
  119. }
  120. },
  121. output: {
  122. // Needed, at the time of writing with webpack 5.54.0, when using node 18.14.1 and later.
  123. hashFunction: 'xxhash64',
  124. path: __dirname + '/desktop/core/src/desktop/static/desktop/js/bundles/hue',
  125. filename: '[name]-bundle-[fullhash].js',
  126. chunkFilename: '[name]-chunk-[fullhash].js',
  127. clean: true,
  128. devtoolModuleFilenameTemplate(info) {
  129. // Prevents absolute paths in the generated sourceMaps
  130. return `webpack:///${info.resourcePath.replace(__dirname, '.')}`;
  131. }
  132. },
  133. performance: {
  134. maxEntrypointSize: 400 * 1024, // 400kb
  135. maxAssetSize: 400 * 1024 // 400kb
  136. },
  137. plugins: getPluginConfig(BUNDLES.HUE).concat([
  138. new CleanWebpackPlugin({
  139. cleanOnceBeforeBuildPatterns: [
  140. `${__dirname}/desktop/core/src/desktop/static/desktop/js/bundles/hue`
  141. ]
  142. })
  143. ]),
  144. resolve: {
  145. extensions: ['.json', '.jsx', '.js', '.tsx', '.ts', '.vue'],
  146. modules: ['node_modules', 'js'],
  147. alias: {
  148. bootstrap: __dirname + '/node_modules/bootstrap-2.3.2/js',
  149. vue$: __dirname + '/node_modules/vue/dist/vue.esm-browser.prod.js'
  150. }
  151. }
  152. };
  153. // To customize build configurations
  154. const EXTEND_CONFIG_FILE = './webpack.config.extend.js';
  155. if (fs.existsSync(EXTEND_CONFIG_FILE)) {
  156. const endedConfig = require(EXTEND_CONFIG_FILE);
  157. endedConfig(config);
  158. console.info('Webpack extended!');
  159. }
  160. module.exports = config;