webpack.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2017-2020 @polkadot/apps authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. /* eslint-disable @typescript-eslint/camelcase */
  5. const fs = require('fs');
  6. const path = require('path');
  7. const merge = require('webpack-merge');
  8. const baseConfig = require('./webpack.base.config');
  9. const { WebpackPluginServe } = require('webpack-plugin-serve');
  10. const findPackages = require('../../scripts/findPackages');
  11. const HtmlWebpackPlugin = require('html-webpack-plugin');
  12. const devtool = false;
  13. const ENV = process.env.NODE_ENV || 'development';
  14. const isProd = ENV === 'production';
  15. const context = __dirname;
  16. const hasPublic = fs.existsSync(path.join(context, 'public'));
  17. const plugins = isProd
  18. ? []
  19. : [
  20. new WebpackPluginServe({
  21. hmr: false, // switch off, Chrome WASM memory leak
  22. liveReload: false, // explict off, overrides hmr
  23. port: 3000,
  24. progress: false, // since we have hmr off, disable
  25. static: path.join(process.cwd(), '/build')
  26. })
  27. ];
  28. module.exports = merge(
  29. baseConfig({
  30. alias: findPackages().reduce((alias, { dir, name }) => {
  31. alias[name] = path.resolve(context, `../${dir}/src`);
  32. return alias;
  33. }, {}),
  34. context
  35. }),
  36. {
  37. devtool,
  38. plugins: plugins.concat([
  39. new HtmlWebpackPlugin({
  40. PAGE_TITLE: 'Polkadot/Substrate Portal',
  41. inject: true,
  42. template: path.join(context, `${hasPublic ? 'public/' : ''}index.html`)
  43. })
  44. ])
  45. }
  46. );