webpack.common.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* global __dirname, module */
  2. const path = require('path');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4. bootstrap_ignore_modules = ['carousel', 'scrollspy'];
  5. BOOTSTRAP_IGNORE_MODULES = (process.env.BOOTSTRAP_IGNORE_MODULES || '').replace(/ /g, '').trim();
  6. if(BOOTSTRAP_IGNORE_MODULES.length > 0)
  7. bootstrap_ignore_modules = bootstrap_ignore_modules.concat(BOOTSTRAP_IGNORE_MODULES.split(','));
  8. module.exports = {
  9. output: {
  10. path: path.resolve(__dirname, 'dist'), // Output path for generated bundles
  11. chunkFilename: '[name].js'
  12. },
  13. entry: path.resolve(__dirname, 'src/entry.js'),
  14. externals: [{
  15. "window": "window"
  16. }],
  17. optimization: {
  18. minimize: true,
  19. minimizer: [new TerserPlugin()]
  20. },
  21. watchOptions: {
  22. ignored: [/dist/, /spec/, /.*\~/]
  23. },
  24. module: {
  25. rules: [
  26. {
  27. test: path.resolve(__dirname, "node_modules/xss/dist/xss"),
  28. use: "exports-loader?filterXSS,filterCSS"
  29. },
  30. {
  31. test: /\.(html|svg)$/,
  32. exclude: /node_modules/,
  33. use: [{
  34. loader: 'lodash-template-webpack-loader',
  35. options: {
  36. "escape": /\{\{\{([\s\S]+?)\}\}\}/g,
  37. "evaluate": /\{\[([\s\S]+?)\]\}/g,
  38. "interpolate": /\{\{([\s\S]+?)\}\}/g,
  39. // By default, template places the values from your data in the
  40. // local scope via the with statement. However, you can specify
  41. // a single variable name with the variable setting. This can
  42. // significantly improve the speed at which a template is able
  43. // to render.
  44. "variable": 'o',
  45. "prependFilenameComment": __dirname
  46. }
  47. }]
  48. }, {
  49. test: /LC_MESSAGES\/converse.po$/,
  50. type: "json",
  51. use: [
  52. {
  53. loader: 'po-loader',
  54. options: {
  55. 'format': 'jed',
  56. 'domain': 'converse'
  57. }
  58. }
  59. ]
  60. }, {
  61. test: /webfonts\/.*\.(woff(2)?|ttf|eot|truetype|svg)(\?v=\d+\.\d+\.\d+)?$/,
  62. use: [
  63. {
  64. loader: 'file-loader',
  65. options: {
  66. name: '[name].[ext]',
  67. outputPath: 'webfonts/'
  68. }
  69. }
  70. ]
  71. }, {
  72. test: /\.scss$/,
  73. use: [
  74. 'style-loader',
  75. {
  76. loader: 'css-loader',
  77. options: {
  78. sourceMap: true
  79. }
  80. },
  81. 'postcss-loader',
  82. {
  83. loader: 'sass-loader',
  84. options: {
  85. includePaths: [
  86. path.resolve(__dirname, 'node_modules/'),
  87. ],
  88. sourceMap: true
  89. }
  90. }
  91. ]
  92. }, {
  93. test: /\.js$/,
  94. exclude: /(node_modules|spec|mockup)/,
  95. use: {
  96. loader: 'babel-loader',
  97. options: {
  98. presets: [
  99. ["@babel/preset-env", {
  100. "targets": {
  101. "browsers": [">1%", "not ie 11", "not op_mini all"]
  102. }
  103. }]
  104. ],
  105. plugins: ['@babel/plugin-syntax-dynamic-import']
  106. }
  107. }
  108. }, {
  109. test: /bootstrap\.native/,
  110. use: {
  111. loader: 'bootstrap.native-loader',
  112. options: {
  113. bs_version: 4,
  114. ignore: bootstrap_ignore_modules
  115. }
  116. }
  117. }],
  118. },
  119. resolve: {
  120. extensions: ['.js'],
  121. modules: [
  122. 'node_modules',
  123. path.resolve(__dirname, "src")
  124. ],
  125. alias: {
  126. "IPv6": path.resolve(__dirname, "node_modules/urijs/src/IPv6"),
  127. "SecondLevelDomains": path.resolve(__dirname, "node_modules/urijs/src/SecondLevelDomains"),
  128. "formdata-polyfill": path.resolve(__dirname, "node_modules/formdata-polyfill/FormData"),
  129. "punycode": path.resolve(__dirname, "node_modules/urijs/src/punycode")
  130. }
  131. }
  132. }