webpack.build.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* global __dirname, module, process */
  2. const ASSET_PATH = process.env.ASSET_PATH || '/dist/'; // eslint-disable-line no-process-env
  3. const CircularDependencyPlugin = require('circular-dependency-plugin');
  4. const CopyWebpackPlugin = require('copy-webpack-plugin');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const common = require("./webpack.common.js");
  7. const path = require('path');
  8. const webpack = require('webpack');
  9. const { merge } = require("webpack-merge");
  10. const plugins = [
  11. new MiniCssExtractPlugin({filename: '../dist/converse.min.css'}),
  12. new MiniCssExtractPlugin({filename: '../dist/converse.css'}),
  13. new CopyWebpackPlugin({
  14. patterns: [
  15. {from: 'node_modules/strophe.js/src/shared-connection-worker.js', to: 'shared-connection-worker.js'},
  16. {from: 'sounds', to: 'sounds'},
  17. {from: 'images/favicon.ico', to: 'images/favicon.ico'},
  18. {from: 'images/custom_emojis', to: 'images/custom_emojis'},
  19. {from: 'logo/conversejs-filled-192.png', to: 'images/logo'},
  20. {from: 'logo/conversejs-filled-512.png', to: 'images/logo'},
  21. {from: 'logo/conversejs-filled-192.svg', to: 'images/logo'},
  22. {from: 'logo/conversejs-filled-512.svg', to: 'images/logo'},
  23. {from: 'logo/conversejs-filled.svg', to: 'images/logo'},
  24. {from: 'logo/conversejs-gold-gradient.svg', to: 'images/logo'},
  25. {from: 'src/shared/styles/webfonts', to: 'webfonts'}
  26. ]
  27. }),
  28. new webpack.DefinePlugin({ // This makes it possible for us to safely use env vars on our code
  29. 'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH)
  30. }),
  31. new CircularDependencyPlugin({
  32. exclude: /node_modules/,
  33. failOnError: true,
  34. allowAsyncCycles: false,
  35. cwd: process.cwd(),
  36. })
  37. ];
  38. module.exports = merge(common, {
  39. plugins,
  40. entry: {
  41. "converse": path.resolve(__dirname, "../src/entry.js"),
  42. "converse.min": path.resolve(__dirname, "../src/entry.js"),
  43. },
  44. output: {
  45. publicPath: ASSET_PATH,
  46. filename: "[name].js",
  47. },
  48. mode: "production",
  49. module: {
  50. rules: [{
  51. test: /\.(js|ts)$/,
  52. use: [{
  53. loader: 'minify-html-literals-loader'
  54. }]
  55. },
  56. {
  57. test: /\.scss$/,
  58. use: [
  59. MiniCssExtractPlugin.loader,
  60. {
  61. loader: 'css-loader',
  62. options: {
  63. url: false,
  64. sourceMap: true
  65. }
  66. },
  67. {
  68. loader: "postcss-loader",
  69. options: { sourceMap: true }
  70. },
  71. {
  72. loader: 'sass-loader',
  73. options: {
  74. sassOptions: {
  75. includePaths: [
  76. path.resolve(__dirname, '../node_modules/'),
  77. path.resolve(__dirname, '../src/')
  78. ]
  79. },
  80. sourceMap: true
  81. }
  82. },
  83. ]
  84. }]
  85. }
  86. });