webpack.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var fs = require('fs');
  2. var webpack = require('webpack');
  3. var path = require('path');
  4. var jqueryShim = new webpack.ProvidePlugin({
  5. $: 'jquery',
  6. jQuery: 'jquery',
  7. 'window.jQuery': 'jquery'
  8. });
  9. var PROD = JSON.parse(process.env.PROD_ENV || '0');
  10. var plugins = [];
  11. if (PROD) {
  12. plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }));
  13. }
  14. // Note that since we are using 'npm install' and stopped using --legacy-bundling,
  15. // we are not ensured which version is installed and where. We will try cloudera-ui
  16. // first, and if it is not there we will let 'require' resolve it. The latter means
  17. // that a version compatible with cloudera-ui and other libraries was installed at the
  18. // top of the node_modules directory.
  19. var lodashDir = path.resolve('node_modules/lodash');
  20. if (!fs.exists(lodashDir)) {
  21. lodashDir = require.resolve('lodash');
  22. }
  23. module.exports = {
  24. devtool: 'source-map',
  25. progress: true,
  26. host: '0.0.0.0',
  27. port: '8080',
  28. resolve: {
  29. extensions: ['', '.json', '.jsx', '.js'],
  30. modulesDirectories: [
  31. 'node_modules',
  32. 'js',
  33. 'desktop/core/src/desktop/static/desktop/js/cui'
  34. ],
  35. alias: {
  36. // any bootstrap modules should really resolve to node_modules/bootstrap/js
  37. bootstrap: 'bootstrap/js',
  38. 'cloudera-ui': 'cui',
  39. _: 'lodash',
  40. komapping: 'knockout.mapping',
  41. 'query-command-supported': 'query-command-supported/src/queryCommandSupported',
  42. pubsub: 'pubsub.js/pubsub'
  43. }
  44. },
  45. entry: {
  46. cui: ['./desktop/core/src/desktop/static/desktop/js/cui.js']
  47. },
  48. output: {
  49. path: './desktop/core/src/desktop/static/desktop/js',
  50. filename: 'cui-bundle.js'
  51. },
  52. module: {
  53. loaders: [
  54. { test: /\.(html)$/, loader: 'html?interpolate&removeComments=false' },
  55. { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' },
  56. { test: /\.css$/, loader: 'style-loader!css-loader' },
  57. { test: /\.(woff2?|ttf|eot|svg)$/, loader: 'file-loader' },
  58. {
  59. test: /\.jsx?$/,
  60. exclude: /node_modules/,
  61. loader: 'babel-loader',
  62. query: {
  63. presets: ['es2015']
  64. }
  65. },
  66. // expose lodash and jquery for knockout templates to access
  67. { test: /lodash$/, loader: 'expose?_' },
  68. { test: /jquery/, loader: 'expose?$!expose?jQuery' },
  69. // needed for moment-timezone
  70. { include: /\.json$/, loaders: ['json-loader'] }
  71. ]
  72. },
  73. plugins: plugins
  74. };