webpack.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const CopyWebpackPlugin = require('copy-webpack-plugin');
  4. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  5. const webpackMerge = require('webpack-merge');
  6. const webpack = require('webpack');
  7. const autoPrefixer = require('autoprefixer');
  8. const outDir = path.resolve(__dirname, 'dist');
  9. const srcDir = path.resolve(__dirname, 'src');
  10. module.exports = function (env, argv) {
  11. const isProductionMode = (argv["mode"] === "production");
  12. const disableMinimize = (env && env.disableMinimize) || false;
  13. const commonConfig = {
  14. devtool: 'source-map',
  15. entry: {
  16. 'changepassword.ng': './src/modules/changepassword/changepassword.module'
  17. // (see production and development specific sections below for more entries)
  18. },
  19. output: {
  20. filename: "[name].js",
  21. path: outDir
  22. },
  23. resolve: {
  24. extensions: [".ts", ".js"]
  25. },
  26. module: {
  27. rules: [
  28. {
  29. test: /.ts$/,
  30. loader: "ts-loader"
  31. },
  32. {
  33. test: /\.ts$/,
  34. enforce: 'pre',
  35. loader: 'tslint-loader'
  36. },
  37. {
  38. test: /index-dev\.html$/,
  39. loader: 'html-loader',
  40. exclude: /node_modules/
  41. },
  42. {
  43. test: /\.html$/,
  44. loader: 'ngtemplate-loader!html-loader',
  45. exclude: /index-dev\.html$/
  46. },
  47. {
  48. test: /\.(scss)$/,
  49. loaders: [ 'style-loader', 'css-loader', 'sass-loader', {
  50. loader: 'postcss-loader',
  51. options: {
  52. plugins: function () {
  53. return [autoPrefixer('last 2 versions')]
  54. }
  55. }
  56. }]
  57. },
  58. {
  59. test: /\.(png|jpg|jpeg|gif|svg)$/,
  60. loaders: [ 'url-loader?limit=25000' ]
  61. }
  62. ]
  63. },
  64. plugins: [
  65. new CopyWebpackPlugin([
  66. { from: 'node_modules/@microfocus/ux-ias/dist/ux-ias.css', to: 'vendor/ux-ias/' },
  67. { from: 'node_modules/@microfocus/ias-icons/dist/ias-icons.css', to: 'vendor/ux-ias/' },
  68. { from: 'node_modules/@microfocus/ias-icons/dist/fonts', to: 'vendor/ux-ias/fonts' }
  69. ])
  70. ],
  71. optimization: {
  72. splitChunks: {
  73. cacheGroups: {
  74. vendor: {
  75. test: /[\\/]node_modules[\\/]/,
  76. name: "vendor",
  77. chunks: "all"
  78. }
  79. }
  80. }
  81. }
  82. };
  83. if (isProductionMode) {
  84. // Production-specific configuration
  85. return webpackMerge(commonConfig, {
  86. entry: {
  87. 'peoplesearch.ng': './src/modules/peoplesearch/main',
  88. 'helpdesk.ng': './src/modules/helpdesk/main'
  89. },
  90. optimization:{
  91. minimize: !disableMinimize,
  92. minimizer: [
  93. new UglifyJsPlugin({
  94. sourceMap: true,
  95. uglifyOptions: {
  96. compress: {warnings: false},
  97. comments: false
  98. }
  99. })
  100. ]
  101. }
  102. });
  103. }
  104. else {
  105. // Development-specific configuration
  106. return webpackMerge(commonConfig, {
  107. entry: {
  108. 'peoplesearch.ng': './src/modules/peoplesearch/main',
  109. 'helpdesk.ng': './src/modules/helpdesk/main'
  110. },
  111. plugins: [
  112. new HtmlWebpackPlugin({
  113. chunks: ['peoplesearch.ng', 'vendor'],
  114. chunksSortMode: 'dependency',
  115. filename: 'peoplesearch.html',
  116. template: 'src/index-dev.html',
  117. inject: 'body',
  118. livereload: true
  119. }),
  120. new HtmlWebpackPlugin({
  121. chunks: ['helpdesk.ng', 'vendor'],
  122. chunksSortMode: 'dependency',
  123. filename: 'helpdesk.html',
  124. template: 'src/index-dev.html',
  125. inject: 'body',
  126. livereload: true
  127. })
  128. ],
  129. });
  130. }
  131. };