123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. const webpack = require('webpack');
  2. const writeFilePlugin = require('write-file-webpack-plugin');
  3. const webpackMerge = require('webpack-merge');
  4. const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
  5. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
  6. const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  7. const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
  8. const WebpackNotifierPlugin = require('webpack-notifier');
  9. const path = require('path');
  10. const sass = require('sass');
  11. const utils = require('./utils.js');
  12. const commonConfig = require('./webpack.common.js');
  13. const ENV = 'development';
  14. module.exports = (options) => webpackMerge(commonConfig({ env: ENV }), {
  15. devtool: 'eval-source-map',
  16. devServer: {
  17. contentBase: './target/www',
  18. proxy: [{
  19. context: [
  20. /* jhipster-needle-add-entity-to-webpack - JHipster will add entity api paths here */
  21. '/api',
  22. '/management',
  23. '/swagger-resources',
  24. '/v2/api-docs',
  25. '/h2-console',
  26. '/auth'
  27. ],
  28. target: `http${options.tls ? 's' : ''}://127.0.0.1:8080`,
  29. secure: false,
  30. changeOrigin: options.tls,
  31. headers: { host: 'localhost:9000' }
  32. }],
  33. stats: options.stats,
  34. watchOptions: {
  35. ignored: /node_modules/
  36. }
  37. },
  38. entry: {
  39. polyfills: './src/main/webapp/app/polyfills',
  40. global: './src/main/webapp/content/scss/global.scss',
  41. main: './src/main/webapp/app/app.main'
  42. },
  43. output: {
  44. path: utils.root('target/www'),
  45. filename: 'app/[name].bundle.js',
  46. chunkFilename: 'app/[id].chunk.js'
  47. },
  48. module: {
  49. rules: [{
  50. test: /\.ts$/,
  51. enforce: 'pre',
  52. loader: 'tslint-loader',
  53. exclude: [/(node_modules)/, new RegExp('reflect-metadata\\' + path.sep + 'Reflect\\.ts')]
  54. },
  55. {
  56. test: /\.ts$/,
  57. use: [
  58. 'angular2-template-loader',
  59. {
  60. loader: 'cache-loader',
  61. options: {
  62. cacheDirectory: path.resolve('target/cache-loader')
  63. }
  64. },
  65. {
  66. loader: 'thread-loader',
  67. options: {
  68. // there should be 1 cpu for the fork-ts-checker-webpack-plugin
  69. workers: require('os').cpus().length - 1
  70. }
  71. },
  72. {
  73. loader: 'ts-loader',
  74. options: {
  75. transpileOnly: true,
  76. happyPackMode: true
  77. }
  78. },
  79. 'angular-router-loader'
  80. ],
  81. exclude: /(node_modules)/
  82. },
  83. {
  84. test: /\.scss$/,
  85. use: ['to-string-loader', 'css-loader', {
  86. loader: 'sass-loader',
  87. options: { implementation: sass }
  88. }],
  89. exclude: /(vendor\.scss|global\.scss)/
  90. },
  91. {
  92. test: /(vendor\.scss|global\.scss)/,
  93. use: ['style-loader', 'css-loader', 'postcss-loader', {
  94. loader: 'sass-loader',
  95. options: { implementation: sass }
  96. }]
  97. },
  98. {
  99. test: /\.css$/,
  100. use: ['to-string-loader', 'css-loader'],
  101. exclude: /(vendor\.css|global\.css)/
  102. },
  103. {
  104. test: /(vendor\.css|global\.css)/,
  105. use: ['style-loader', 'css-loader']
  106. }]
  107. },
  108. stats: process.env.JHI_DISABLE_WEBPACK_LOGS ? 'none' : options.stats,
  109. plugins: [
  110. process.env.JHI_DISABLE_WEBPACK_LOGS
  111. ? null
  112. : new SimpleProgressWebpackPlugin({
  113. format: options.stats === 'minimal' ? 'compact' : 'expanded'
  114. }),
  115. new FriendlyErrorsWebpackPlugin(),
  116. new ForkTsCheckerWebpackPlugin(),
  117. new BrowserSyncPlugin({
  118. host: 'localhost',
  119. port: 9000,
  120. proxy: {
  121. target: 'http://localhost:9060'
  122. },
  123. socket: {
  124. clients: {
  125. heartbeatTimeout: 60000
  126. }
  127. }
  128. }, {
  129. reload: false
  130. }),
  131. new webpack.ContextReplacementPlugin(
  132. /angular(\\|\/)core(\\|\/)/,
  133. path.resolve(__dirname, './src/main/webapp')
  134. ),
  135. new writeFilePlugin(),
  136. new webpack.WatchIgnorePlugin([
  137. utils.root('src/test'),
  138. ]),
  139. new WebpackNotifierPlugin({
  140. title: 'JHipster',
  141. contentImage: path.join(__dirname, 'logo-jhipster.png')
  142. })
  143. ].filter(Boolean),
  144. mode: 'development'
  145. });