webpack.common.js 3.5 KB

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