webpack.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 commonConfig = {
  13. devtool: 'source-map',
  14. entry: {
  15. 'changepassword.ng': './src/modules/changepassword/changepassword.module',
  16. 'configeditor.ng': './src/modules/configeditor/configeditor.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. test: [
  64. require.resolve("textangular"),
  65. require.resolve("textangular/dist/textAngular-sanitize")
  66. ],
  67. use: "imports-loader?angular"
  68. }
  69. ]
  70. },
  71. plugins: [
  72. new CopyWebpackPlugin([
  73. { from: 'node_modules/@microfocus/ux-ias/dist/ux-ias.css', to: 'vendor/ux-ias/' },
  74. { from: 'node_modules/@microfocus/ias-icons/dist/ias-icons.css', to: 'vendor/ux-ias/' },
  75. { from: 'node_modules/@microfocus/ias-icons/dist/fonts', to: 'vendor/ux-ias/fonts' },
  76. { from: 'node_modules/textangular/dist/textAngular.css', to: 'vendor/textangular' }
  77. ])
  78. ],
  79. optimization: {
  80. splitChunks: {
  81. cacheGroups: {
  82. vendor: {
  83. test: /[\\/]node_modules[\\/]/,
  84. name: "vendor",
  85. chunks: "all"
  86. }
  87. }
  88. }
  89. }
  90. };
  91. if (isProductionMode) {
  92. // Production-specific configuration
  93. return webpackMerge(commonConfig, {
  94. entry: {
  95. 'peoplesearch.ng': './src/modules/peoplesearch/main',
  96. 'helpdesk.ng': './src/modules/helpdesk/main'
  97. },
  98. plugins: [
  99. new UglifyJsPlugin({
  100. sourceMap: true,
  101. uglifyOptions: {
  102. compress: {warnings: false},
  103. comments: false
  104. }
  105. })
  106. ]
  107. });
  108. }
  109. else {
  110. // Development-specific configuration
  111. return webpackMerge(commonConfig, {
  112. entry: {
  113. 'peoplesearch.ng': './src/modules/peoplesearch/main.dev',
  114. 'helpdesk.ng': './src/modules/helpdesk/main.dev'
  115. },
  116. plugins: [
  117. new HtmlWebpackPlugin({
  118. chunks: ['peoplesearch.ng', 'vendor'],
  119. chunksSortMode: 'dependency',
  120. filename: 'peoplesearch.html',
  121. template: 'src/index-dev.html',
  122. inject: 'body',
  123. livereload: true
  124. }),
  125. new HtmlWebpackPlugin({
  126. chunks: ['helpdesk.ng', 'vendor'],
  127. chunksSortMode: 'dependency',
  128. filename: 'helpdesk.html',
  129. template: 'src/index-dev.html',
  130. inject: 'body',
  131. livereload: true
  132. })
  133. ],
  134. });
  135. }
  136. };