webpack.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 CleanWebpackPlugin = require('clean-webpack-plugin');
  18. const {
  19. BUNDLES,
  20. getPluginConfig,
  21. splitChunksName
  22. } = require('./desktop/core/src/desktop/js/webpack/configUtils');
  23. const config = {
  24. devtool: 'cheap-source-map',
  25. entry: {
  26. hue: { import: './desktop/core/src/desktop/js/hue.js' },
  27. editor: { import: './desktop/core/src/desktop/js/apps/editor/app.js', dependOn: 'hue' },
  28. notebook: { import: './desktop/core/src/desktop/js/apps/notebook/app.js', dependOn: 'hue' },
  29. tableBrowser: {
  30. import: './desktop/core/src/desktop/js/apps/tableBrowser/app.js',
  31. dependOn: 'hue'
  32. },
  33. jobBrowser: { import: './desktop/core/src/desktop/js/apps/jobBrowser/app.js', dependOn: 'hue' }
  34. },
  35. mode: 'development',
  36. module: {
  37. rules: [
  38. {
  39. test: /\.vue$/,
  40. exclude: /node_modules/,
  41. use: 'vue-loader'
  42. },
  43. {
  44. test: /\.(jsx?|tsx?)$/,
  45. exclude: /node_modules/,
  46. use: [{
  47. loader: 'babel-loader',
  48. options: {
  49. presets: ['@babel/preset-env', '@babel/preset-react']
  50. }
  51. }]
  52. },
  53. {
  54. test: /\.(jsx?|tsx?)$/,
  55. enforce: "pre",
  56. use: ["source-map-loader"],
  57. },
  58. {
  59. test: /\.scss$/,
  60. exclude: /node_modules/,
  61. use: ['style-loader', 'css-loader', 'sass-loader']
  62. },
  63. {
  64. test: /\.html$/,
  65. exclude: /node_modules/,
  66. use: { loader: 'html', options: { interpolater: true, removeComments: false } }
  67. }
  68. ]
  69. },
  70. optimization: {
  71. minimize: false,
  72. splitChunks: {
  73. chunks: 'all',
  74. name: splitChunksName,
  75. maxSize: 1000000,
  76. hidePathInfo: true
  77. }
  78. },
  79. output: {
  80. path: __dirname + '/desktop/core/src/desktop/static/desktop/js/bundles/hue',
  81. filename: '[name]-bundle-[fullhash].js',
  82. chunkFilename: '[name]-chunk-[fullhash].js',
  83. clean: true,
  84. devtoolModuleFilenameTemplate(info) {
  85. // Prevents absolute paths in the generated sourceMaps
  86. return `webpack:///${info.resourcePath.replace(__dirname, '.')}`;
  87. }
  88. },
  89. performance: {
  90. maxEntrypointSize: 400 * 1024, // 400kb
  91. maxAssetSize: 400 * 1024 // 400kb
  92. },
  93. plugins: getPluginConfig(BUNDLES.HUE).concat([
  94. new CleanWebpackPlugin([`${__dirname}/desktop/core/src/desktop/static/desktop/js/bundles/hue`])
  95. ]),
  96. resolve: {
  97. extensions: ['.json', '.jsx', '.js', '.tsx', '.ts', '.vue'],
  98. modules: ['node_modules', 'js'],
  99. alias: {
  100. bootstrap: __dirname + '/node_modules/bootstrap-2.3.2/js',
  101. vue$: __dirname + '/node_modules/vue/dist/vue.esm-browser.prod.js'
  102. }
  103. }
  104. };
  105. // To customize build configurations
  106. const EXTEND_CONFIG_FILE = './webpack.config.extend.js';
  107. if (fs.existsSync(EXTEND_CONFIG_FILE)) {
  108. const endedConfig = require(EXTEND_CONFIG_FILE);
  109. endedConfig(config);
  110. console.info('Webpack extended!');
  111. }
  112. module.exports = config;