webpack.common.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* global __dirname, module, process */
  2. const ASSET_PATH = process.env.ASSET_PATH || '/dist/'; // eslint-disable-line no-process-env
  3. const webpack = require('webpack');
  4. const TerserPlugin = require("terser-webpack-plugin");
  5. const path = require('path');
  6. let bootstrap_ignore_modules = ['carousel', 'scrollspy', 'tooltip', 'toast'];
  7. const BOOTSTRAP_IGNORE_MODULES = (process.env.BOOTSTRAP_IGNORE_MODULES || '').replace(/ /g, '').trim();
  8. if (BOOTSTRAP_IGNORE_MODULES.length > 0) {
  9. bootstrap_ignore_modules = bootstrap_ignore_modules.concat(BOOTSTRAP_IGNORE_MODULES.split(','));
  10. }
  11. const plugins = [
  12. new webpack.DefinePlugin({ // This makes it possible for us to safely use env vars on our code
  13. 'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH)
  14. }),
  15. ];
  16. module.exports = {
  17. plugins,
  18. output: {
  19. path: path.resolve(__dirname, '../dist'), // Output path for generated bundles
  20. publicPath: ASSET_PATH,
  21. chunkFilename: '[name].js'
  22. },
  23. devtool: "source-map",
  24. optimization: {
  25. minimize: true,
  26. minimizer: [
  27. new TerserPlugin({
  28. include: /\.min\.js$/
  29. })
  30. ],
  31. },
  32. externals: [{
  33. "window": "window"
  34. }],
  35. watchOptions: {
  36. ignored: /dist/,
  37. },
  38. module: {
  39. rules: [{
  40. test: /LC_MESSAGES[\\/]converse.po$/,
  41. type: "json",
  42. use: [
  43. {
  44. loader: 'po-loader',
  45. options: {
  46. 'format': 'jed',
  47. 'domain': 'converse'
  48. }
  49. }
  50. ]
  51. }, {
  52. test: /webfonts[\\/].*\.(woff(2)?|ttf|eot|truetype|svg)(\?v=\d+\.\d+\.\d+)?$/,
  53. type: 'asset/resource',
  54. generator: {
  55. filename: '[name][ext]',
  56. publicPath: 'webfonts/',
  57. outputPath: 'webfonts/'
  58. }
  59. }, {
  60. test: /\.scss$/,
  61. use: [
  62. 'style-loader',
  63. {
  64. loader: 'css-loader',
  65. options: {
  66. url: false,
  67. sourceMap: true
  68. }
  69. },
  70. {
  71. loader: "postcss-loader",
  72. options: { sourceMap: true }
  73. },
  74. {
  75. loader: 'sass-loader',
  76. options: {
  77. sassOptions: {
  78. includePaths: [
  79. path.resolve(__dirname, '../node_modules/'),
  80. path.resolve(__dirname, '../src/')
  81. ]
  82. },
  83. sourceMap: true
  84. }
  85. },
  86. ]
  87. }, {
  88. test: /\.js$/,
  89. include: [
  90. /src/,
  91. /node_modules\/mergebounce/,
  92. /node_modules\/lit-html/,
  93. /node_modules\/strophe/,
  94. /node_modules\/pluggable/,
  95. /node_modules\/@converse/,
  96. ],
  97. use: {
  98. loader: 'babel-loader'
  99. }
  100. }, {
  101. test: /bootstrap\.native/,
  102. use: {
  103. loader: 'bootstrap.native-loader',
  104. options: {
  105. bs_version: 4,
  106. ignore: bootstrap_ignore_modules
  107. }
  108. }
  109. }],
  110. },
  111. resolve: {
  112. extensions: ['.js'],
  113. modules: [
  114. 'node_modules',
  115. path.resolve(__dirname, "../src")
  116. ],
  117. alias: {
  118. "IPv6": path.resolve(__dirname, "../node_modules/urijs/src/IPv6"),
  119. "SecondLevelDomains": path.resolve(__dirname, "../node_modules/urijs/src/SecondLevelDomains"),
  120. "punycode": path.resolve(__dirname, "../node_modules/urijs/src/punycode"),
  121. "./shims.js": path.resolve(__dirname, "../src/strophe-shims.js"),
  122. "./shims": path.resolve(__dirname, "../src/strophe-shims.js"),
  123. }
  124. }
  125. }