webpack.common.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: [
  32. path.posix.resolve(__dirname, '../develop-eggs'),
  33. path.posix.resolve(__dirname, '../dist'),
  34. path.posix.resolve(__dirname, '../docs'),
  35. path.posix.resolve(__dirname, '../node_modules'),
  36. path.posix.resolve(__dirname, '../src/headless/dist'),
  37. path.posix.resolve(__dirname, '../src/headless/node_modules'),
  38. path.posix.resolve(__dirname, '../webpack'),
  39. ],
  40. },
  41. module: {
  42. rules: [{
  43. test: /LC_MESSAGES[\\/]converse.po$/,
  44. type: "json",
  45. use: [
  46. {
  47. loader: 'po-loader',
  48. options: {
  49. 'format': 'jed',
  50. 'domain': 'converse'
  51. }
  52. }
  53. ]
  54. }, {
  55. test: /webfonts[\\/].*\.(woff(2)?|ttf|eot|truetype|svg)(\?v=\d+\.\d+\.\d+)?$/,
  56. type: 'asset/resource',
  57. generator: {
  58. filename: '[name][ext]',
  59. publicPath: 'webfonts/',
  60. outputPath: 'webfonts/'
  61. }
  62. }, {
  63. test: /\.scss$/,
  64. use: [
  65. 'style-loader',
  66. {
  67. loader: 'css-loader',
  68. options: {
  69. url: false,
  70. sourceMap: true
  71. }
  72. },
  73. {
  74. loader: "postcss-loader",
  75. options: { sourceMap: true }
  76. },
  77. {
  78. loader: 'sass-loader',
  79. options: {
  80. sassOptions: {
  81. silenceDeprecations: ['color-functions', 'global-builtin', 'import', 'mixed-decls'],
  82. includePaths: [
  83. path.resolve(__dirname, '../node_modules/'),
  84. path.resolve(__dirname, '../src/')
  85. ]
  86. },
  87. sourceMap: true
  88. }
  89. },
  90. ]
  91. }, {
  92. test: /\.js$/,
  93. include: [
  94. /src/,
  95. /node_modules\/mergebounce/,
  96. /node_modules\/lit-html/,
  97. /node_modules\/strophe/,
  98. /node_modules\/pluggable/,
  99. /node_modules\/@converse/,
  100. ],
  101. use: {
  102. loader: 'babel-loader'
  103. }
  104. }],
  105. },
  106. resolve: {
  107. extensions: ['.js'],
  108. modules: [
  109. 'node_modules',
  110. path.resolve(__dirname, "../src")
  111. ],
  112. alias: {
  113. "IPv6": path.resolve(__dirname, "../node_modules/urijs/src/IPv6"),
  114. "SecondLevelDomains": path.resolve(__dirname, "../node_modules/urijs/src/SecondLevelDomains"),
  115. "punycode": path.resolve(__dirname, "../node_modules/urijs/src/punycode"),
  116. "./shims.js": path.resolve(__dirname, "../src/strophe-shims.js"),
  117. "./shims": path.resolve(__dirname, "../src/strophe-shims.js"),
  118. }
  119. }
  120. }