webpack.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. storageBrowser: {
  35. import: './desktop/core/src/desktop/js/apps/storageBrowser/app.js',
  36. dependOn: 'hue'
  37. },
  38. jobBrowser: { import: './desktop/core/src/desktop/js/apps/jobBrowser/app.js', dependOn: 'hue' }
  39. },
  40. mode: 'development',
  41. module: {
  42. rules: [
  43. {
  44. test: /\.vue$/,
  45. exclude: /node_modules/,
  46. use: 'vue-loader'
  47. },
  48. {
  49. test: /\.(jsx?|tsx?)$/,
  50. exclude: /node_modules/,
  51. use: [{
  52. loader: 'babel-loader',
  53. options: {
  54. presets: ['@babel/preset-env', '@babel/preset-react']
  55. }
  56. }]
  57. },
  58. {
  59. test: /\.(jsx?|tsx?)$/,
  60. enforce: "pre",
  61. use: ["source-map-loader"],
  62. },
  63. {
  64. test: /\.scss$/,
  65. exclude: /node_modules/,
  66. use: ['style-loader', 'css-loader', {
  67. loader: 'sass-loader',
  68. options: {
  69. sassOptions: {
  70. includePaths: [
  71. 'desktop/core/src/desktop/js/components/styles',
  72. 'node_modules',
  73. ],
  74. },
  75. },
  76. },]
  77. },
  78. {
  79. test: /\.less$/i,
  80. use: [
  81. { loader: "style-loader" },
  82. { loader: "css-loader" },
  83. {
  84. loader: "less-loader",
  85. options: {
  86. lessOptions: {
  87. // This is not ideal but required by antd library
  88. javascriptEnabled: true,
  89. }
  90. }
  91. }
  92. ],
  93. },
  94. {
  95. test: /\.html$/,
  96. exclude: /node_modules/,
  97. use: { loader: 'html', options: { interpolater: true, removeComments: false } }
  98. }
  99. ]
  100. },
  101. optimization: {
  102. minimize: false,
  103. splitChunks: {
  104. chunks: 'all',
  105. name: splitChunksName,
  106. maxSize: 1000000,
  107. hidePathInfo: true
  108. }
  109. },
  110. output: {
  111. // Needed, at the time of writing with webpack 5.54.0, when using node 18.14.1 and later.
  112. hashFunction: 'xxhash64',
  113. path: __dirname + '/desktop/core/src/desktop/static/desktop/js/bundles/hue',
  114. filename: '[name]-bundle-[fullhash].js',
  115. chunkFilename: '[name]-chunk-[fullhash].js',
  116. clean: true,
  117. devtoolModuleFilenameTemplate(info) {
  118. // Prevents absolute paths in the generated sourceMaps
  119. return `webpack:///${info.resourcePath.replace(__dirname, '.')}`;
  120. }
  121. },
  122. performance: {
  123. maxEntrypointSize: 400 * 1024, // 400kb
  124. maxAssetSize: 400 * 1024 // 400kb
  125. },
  126. plugins: getPluginConfig(BUNDLES.HUE).concat([
  127. new CleanWebpackPlugin([`${__dirname}/desktop/core/src/desktop/static/desktop/js/bundles/hue`]),
  128. ]),
  129. resolve: {
  130. extensions: ['.json', '.jsx', '.js', '.tsx', '.ts', '.vue'],
  131. modules: ['node_modules', 'js'],
  132. alias: {
  133. bootstrap: __dirname + '/node_modules/bootstrap-2.3.2/js',
  134. vue$: __dirname + '/node_modules/vue/dist/vue.esm-browser.prod.js'
  135. }
  136. }
  137. };
  138. // To customize build configurations
  139. const EXTEND_CONFIG_FILE = './webpack.config.extend.js';
  140. if (fs.existsSync(EXTEND_CONFIG_FILE)) {
  141. const endedConfig = require(EXTEND_CONFIG_FILE);
  142. endedConfig(config);
  143. console.info('Webpack extended!');
  144. }
  145. module.exports = config;