webpack.config.mjs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import * as fs from 'fs'
  2. import * as path from 'path'
  3. import wp from 'webpack'
  4. import * as url from 'url'
  5. const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
  6. import { AngularWebpackPlugin } from '@ngtools/webpack'
  7. import { createEs2015LinkerPlugin } from '@angular/compiler-cli/linker/babel'
  8. const linkerPlugin = createEs2015LinkerPlugin({
  9. linkerJitMode: true,
  10. fileSystem: {
  11. resolve: path.resolve,
  12. exists: fs.existsSync,
  13. dirname: path.dirname,
  14. relative: path.relative,
  15. readFile: fs.readFileSync,
  16. },
  17. })
  18. export default () => ({
  19. name: 'tabby',
  20. target: 'node',
  21. entry: {
  22. 'index.ignore': 'file-loader?name=index.html!pug-html-loader!' + path.resolve(__dirname, './index.pug'),
  23. sentry: path.resolve(__dirname, 'lib/sentry.ts'),
  24. preload: path.resolve(__dirname, 'src/entry.preload.ts'),
  25. bundle: path.resolve(__dirname, 'src/entry.ts'),
  26. },
  27. mode: process.env.TABBY_DEV ? 'development' : 'production',
  28. optimization:{
  29. minimize: false,
  30. },
  31. context: __dirname,
  32. devtool: 'source-map',
  33. output: {
  34. path: path.join(__dirname, 'dist'),
  35. pathinfo: true,
  36. filename: '[name].js',
  37. publicPath: 'auto',
  38. },
  39. resolve: {
  40. modules: ['src/', 'node_modules', '../node_modules', 'assets/'].map(x => path.join(__dirname, x)),
  41. extensions: ['.ts', '.js'],
  42. },
  43. module: {
  44. rules: [
  45. {
  46. test: /\.(m?)js$/,
  47. loader: 'babel-loader',
  48. options: {
  49. plugins: [linkerPlugin],
  50. compact: false,
  51. cacheDirectory: true,
  52. },
  53. resolve: {
  54. fullySpecified: false,
  55. },
  56. },
  57. {
  58. test: /\.ts$/,
  59. use: {
  60. loader: '@ngtools/webpack',
  61. },
  62. },
  63. { test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
  64. { test: /\.css$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
  65. {
  66. test: /\.(png|svg|ttf|eot|otf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  67. type: 'asset',
  68. },
  69. ],
  70. },
  71. externals: {
  72. '@electron/remote': 'commonjs @electron/remote',
  73. 'v8-compile-cache': 'commonjs v8-compile-cache',
  74. child_process: 'commonjs child_process',
  75. electron: 'commonjs electron',
  76. fs: 'commonjs fs',
  77. module: 'commonjs module',
  78. mz: 'commonjs mz',
  79. path: 'commonjs path',
  80. },
  81. plugins: [
  82. new wp.optimize.ModuleConcatenationPlugin(),
  83. new wp.DefinePlugin({
  84. 'process.type': '"renderer"',
  85. }),
  86. new AngularWebpackPlugin({
  87. tsconfig: path.resolve(__dirname, 'tsconfig.json'),
  88. directTemplateLoading: false,
  89. jitMode: true,
  90. })
  91. ],
  92. })