You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack.config.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. /* eslint-disable import/no-extraneous-dependencies */
  21. const path = require('path');
  22. const CleanWebpackPlugin = require('clean-webpack-plugin');
  23. const CopyWebpackPlugin = require('copy-webpack-plugin');
  24. const HtmlWebpackPlugin = require('html-webpack-plugin');
  25. const webpack = require('webpack');
  26. const InterpolateHtmlPlugin = require('./InterpolateHtmlPlugin');
  27. const paths = require('./paths');
  28. const utils = require('./utils');
  29. module.exports = ({ production = true }) => ({
  30. mode: production ? 'production' : 'development',
  31. devtool: production ? 'source-map' : 'cheap-module-source-map',
  32. resolve: {
  33. // Add '.ts' and '.tsx' as resolvable extensions.
  34. extensions: ['.ts', '.tsx', '.js', '.json']
  35. },
  36. entry: [
  37. !production && require.resolve('react-dev-utils/webpackHotDevClient'),
  38. require.resolve('./polyfills'),
  39. !production && require.resolve('react-error-overlay'),
  40. './src/main/js/index.js'
  41. ].filter(Boolean),
  42. output: {
  43. path: paths.appBuild,
  44. pathinfo: !production,
  45. publicPath: paths.publicPath,
  46. filename: production ? 'js/[name].[chunkhash:8].js' : 'js/[name].js',
  47. chunkFilename: production ? 'js/[name].[chunkhash:8].chunk.js' : 'js/[name].chunk.js'
  48. },
  49. module: {
  50. rules: [
  51. {
  52. test: /(\.js$|\.ts(x?)$)/,
  53. exclude: /(node_modules|libs)/,
  54. use: [
  55. { loader: 'babel-loader' },
  56. {
  57. loader: 'ts-loader',
  58. options: { transpileOnly: true }
  59. }
  60. ]
  61. },
  62. {
  63. test: /\.css$/,
  64. use: ['style-loader', utils.cssLoader({ production }), utils.postcssLoader()].filter(
  65. Boolean
  66. )
  67. }
  68. ].filter(Boolean)
  69. },
  70. plugins: [
  71. production && new CleanWebpackPlugin(),
  72. production &&
  73. new CopyWebpackPlugin([
  74. { from: paths.appPublic, to: paths.appBuild, ignore: [paths.appHtml] },
  75. { from: paths.jsLib, to: paths.jsBuild }
  76. ]),
  77. new HtmlWebpackPlugin({
  78. inject: false,
  79. template: paths.appHtml,
  80. minify: utils.minifyParams({ production })
  81. }),
  82. // keep `InterpolateHtmlPlugin` after `HtmlWebpackPlugin`
  83. !production && new InterpolateHtmlPlugin({ WEB_CONTEXT: '' }),
  84. !production && new webpack.HotModuleReplacementPlugin()
  85. ].filter(Boolean)
  86. });