webpack.config.main.mjs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. fs: 'commonjs fs',
  45. glasstron: 'commonjs glasstron',
  46. mz: 'commonjs mz',
  47. npm: 'commonjs npm',
  48. 'node:os': 'commonjs os',
  49. 'node-pty': 'commonjs node-pty',
  50. path: 'commonjs path',
  51. util: 'commonjs util',
  52. 'source-map-support': 'commonjs source-map-support',
  53. 'windows-swca': 'commonjs windows-swca',
  54. 'windows-native-registry': 'commonjs windows-native-registry',
  55. '@tabby-gang/windows-blurbehind': 'commonjs @tabby-gang/windows-blurbehind',
  56. 'yargs/yargs': 'commonjs yargs/yargs',
  57. },
  58. plugins: [
  59. new wp.optimize.ModuleConcatenationPlugin(),
  60. new wp.DefinePlugin({
  61. 'process.type': '"main"',
  62. }),
  63. ],
  64. }
  65. if (process.env.BUNDLE_ANALYZER) {
  66. config.plugins.push(new BundleAnalyzerPlugin())
  67. }
  68. export default () => config