webpack.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const path = require('path')
  2. const nodeExternals = require('webpack-node-externals')
  3. const CopyWebpackPlugin = require('copy-webpack-plugin')
  4. module.exports = {
  5. entry: {
  6. 'api/build': './src/api/build.ts',
  7. 'api/dev': './src/api/dev.ts',
  8. 'api/init': './src/api/init.ts',
  9. 'api/recipes': './src/api/recipes/index.ts',
  10. 'api/recipes/install': './src/api/recipes/install.ts',
  11. 'api/tauricon': './src/api/tauricon.ts',
  12. 'api/info': './src/api/info.ts',
  13. 'api/dependency-manager': './src/api/dependency-manager/index.ts',
  14. 'helpers/tauri-config': './src/helpers/tauri-config.ts',
  15. 'helpers/spawn': './src/helpers/spawn.ts'
  16. },
  17. mode: process.env.NODE_ENV || 'development',
  18. devtool: 'source-map',
  19. module: {
  20. rules: [
  21. {
  22. test: /\.tsx?$/,
  23. use: 'ts-loader',
  24. exclude: /node_modules/
  25. },
  26. {
  27. test: /(templates|api)[\\/].+\.js/,
  28. use: 'raw-loader'
  29. },
  30. {
  31. test: /\.toml?$/,
  32. use: 'toml-loader'
  33. }
  34. ]
  35. },
  36. node: false,
  37. resolve: {
  38. extensions: ['.ts', '.js']
  39. },
  40. output: {
  41. library: 'tauri',
  42. libraryTarget: 'umd',
  43. filename: '[name].js',
  44. path: path.resolve(__dirname, 'dist')
  45. },
  46. externals: [nodeExternals()],
  47. target: 'node',
  48. plugins: [
  49. new CopyWebpackPlugin({
  50. patterns: [
  51. {
  52. from: './src/types/config.validator.ts',
  53. to: '../src/types/config.schema.json',
  54. transform(content) {
  55. return schemaParser('TauriConfigSchema', content.toString())
  56. }
  57. }
  58. ]
  59. })
  60. ]
  61. }
  62. function schemaParser(schemaName, content) {
  63. const lines = content.split('\n')
  64. const output = []
  65. for (const line of lines) {
  66. if (line === `export const ${schemaName} = {`) {
  67. output.push('{')
  68. } else if (output.length) {
  69. if (line === '};') {
  70. output.push('}')
  71. break
  72. }
  73. output.push(line)
  74. }
  75. }
  76. return output.join('\n')
  77. }