webpack.common.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const webpack = require('webpack');
  2. const CopyWebpackPlugin = require('copy-webpack-plugin');
  3. const HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const rxPaths = require('rxjs/_esm5/path-mapping');
  5. const MergeJsonWebpackPlugin = require("merge-jsons-webpack-plugin");
  6. const utils = require('./utils.js');
  7. module.exports = (options) => ({
  8. resolve: {
  9. extensions: ['.ts', '.js'],
  10. modules: ['node_modules'],
  11. alias: {
  12. app: utils.root('src/main/webapp/app/'),
  13. ...rxPaths()
  14. }
  15. },
  16. stats: {
  17. children: false
  18. },
  19. module: {
  20. rules: [
  21. {
  22. test: /\.html$/,
  23. loader: 'html-loader',
  24. options: {
  25. minimize: true,
  26. caseSensitive: true,
  27. removeAttributeQuotes:false,
  28. minifyJS:false,
  29. minifyCSS:false
  30. },
  31. exclude: /(src\/main\/webapp\/index.html)/
  32. },
  33. {
  34. test: /\.(jpe?g|png|gif|svg|woff2?|ttf|eot)$/i,
  35. loader: 'file-loader',
  36. options: {
  37. digest: 'hex',
  38. hash: 'sha512',
  39. name: 'content/[hash].[ext]'
  40. }
  41. },
  42. {
  43. test: /manifest.webapp$/,
  44. loader: 'file-loader',
  45. options: {
  46. name: 'manifest.webapp'
  47. }
  48. },
  49. // Ignore warnings about System.import in Angular
  50. { test: /[\/\\]@angular[\/\\].+\.js$/, parser: { system: true } },
  51. ]
  52. },
  53. plugins: [
  54. new webpack.DefinePlugin({
  55. 'process.env': {
  56. NODE_ENV: `'${options.env}'`,
  57. BUILD_TIMESTAMP: `'${new Date().getTime()}'`,
  58. VERSION: `'${utils.parseVersion()}'`,
  59. DEBUG_INFO_ENABLED: options.env === 'development',
  60. // The root URL for API calls, ending with a '/' - for example: `"https://www.jhipster.tech:8081/myservice/"`.
  61. // If this URL is left empty (""), then it will be relative to the current context.
  62. // If you use an API server, in `prod` mode, you will need to enable CORS
  63. // (see the `jhipster.cors` common JHipster property in the `application-*.yml` configurations)
  64. SERVER_API_URL: `''`
  65. }
  66. }),
  67. new CopyWebpackPlugin([
  68. { from: './node_modules/swagger-ui/dist/css', to: 'swagger-ui/dist/css' },
  69. { from: './node_modules/swagger-ui/dist/lib', to: 'swagger-ui/dist/lib' },
  70. { from: './node_modules/swagger-ui/dist/swagger-ui.min.js', to: 'swagger-ui/dist/swagger-ui.min.js' },
  71. { from: './src/main/webapp/swagger-ui/', to: 'swagger-ui' },
  72. { from: './src/main/webapp/content/', to: 'content' },
  73. { from: './src/main/webapp/favicon.ico', to: 'favicon.ico' },
  74. { from: './src/main/webapp/manifest.webapp', to: 'manifest.webapp' },
  75. // jhipster-needle-add-assets-to-webpack - JHipster will add/remove third-party resources in this array
  76. { from: './src/main/webapp/robots.txt', to: 'robots.txt' }
  77. ]),
  78. new MergeJsonWebpackPlugin({
  79. output: {
  80. groupBy: [
  81. { pattern: "./src/main/webapp/i18n/en/*.json", fileName: "./i18n/en.json" }
  82. // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array
  83. ]
  84. }
  85. }),
  86. new HtmlWebpackPlugin({
  87. template: './src/main/webapp/index.html',
  88. chunks: ['vendors', 'polyfills', 'main', 'global'],
  89. chunksSortMode: 'manual',
  90. inject: 'body'
  91. })
  92. ]
  93. });