webpack.config.main.mjs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import * as path from 'path'
  2. import wp from 'webpack'
  3. import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
  4. import * as url from 'url'
  5. const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
  6. const config = {
  7. name: 'tabby-main',
  8. target: 'electron-main',
  9. entry: {
  10. main: path.resolve(__dirname, 'lib/index.ts'),
  11. },
  12. mode: process.env.TABBY_DEV ? 'development' : 'production',
  13. context: __dirname,
  14. devtool: 'source-map',
  15. output: {
  16. path: path.join(__dirname, 'dist'),
  17. pathinfo: true,
  18. filename: '[name].js',
  19. },
  20. resolve: {
  21. modules: ['lib/', 'node_modules', '../node_modules'].map(x => path.join(__dirname, x)),
  22. extensions: ['.ts', '.js'],
  23. },
  24. module: {
  25. rules: [
  26. {
  27. test: /\.ts$/,
  28. use: {
  29. loader: 'ts-loader',
  30. options: {
  31. configFile: path.resolve(__dirname, 'tsconfig.main.json'),
  32. },
  33. },
  34. },
  35. ],
  36. },
  37. externals: {
  38. 'v8-compile-cache': 'commonjs v8-compile-cache',
  39. 'any-promise': 'commonjs any-promise',
  40. electron: 'commonjs electron',
  41. 'electron-config': 'commonjs electron-config',
  42. 'electron-debug': 'commonjs electron-debug',
  43. 'electron-promise-ipc': 'commonjs electron-promise-ipc',
  44. 'electron-updater': 'commonjs electron-updater',
  45. fs: 'commonjs fs',
  46. glasstron: 'commonjs glasstron',
  47. mz: 'commonjs mz',
  48. npm: 'commonjs npm',
  49. 'node:os': 'commonjs os',
  50. 'node-pty': 'commonjs node-pty',
  51. path: 'commonjs path',
  52. util: 'commonjs util',
  53. 'source-map-support': 'commonjs source-map-support',
  54. 'windows-swca': 'commonjs windows-swca',
  55. 'windows-native-registry': 'commonjs windows-native-registry',
  56. '@tabby-gang/windows-blurbehind': 'commonjs @tabby-gang/windows-blurbehind',
  57. 'yargs/yargs': 'commonjs yargs/yargs',
  58. },
  59. plugins: [
  60. new wp.optimize.ModuleConcatenationPlugin(),
  61. new wp.DefinePlugin({
  62. 'process.type': '"main"',
  63. }),
  64. ],
  65. }
  66. if (process.env.BUNDLE_ANALYZER) {
  67. config.plugins.push(new BundleAnalyzerPlugin())
  68. }
  69. export default () => config