webpack.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. test: /\.tsx?$/,
  22. use: 'ts-loader',
  23. exclude: /node_modules/
  24. },
  25. {
  26. test: /(templates|api)[\\/].+\.js/,
  27. use: 'raw-loader'
  28. },
  29. {
  30. test: /\.toml?$/,
  31. use: 'toml-loader'
  32. }
  33. ]
  34. },
  35. node: false,
  36. resolve: {
  37. extensions: ['.ts', '.js']
  38. },
  39. output: {
  40. library: 'tauri',
  41. libraryTarget: 'umd',
  42. filename: '[name].js',
  43. path: path.resolve(__dirname, 'dist')
  44. },
  45. externals: [nodeExternals()],
  46. target: 'node',
  47. plugins: [
  48. new CopyWebpackPlugin({
  49. patterns: [{
  50. from: './src/types/config.validator.ts',
  51. to: '../src/types/config.schema.json',
  52. transform(content) {
  53. return schemaParser('TauriConfigSchema', content.toString())
  54. }
  55. }]
  56. })
  57. ]
  58. }
  59. function schemaParser(schemaName, content) {
  60. const lines = content.split('\n')
  61. const output = []
  62. for (const line of lines) {
  63. if (line === `export const ${schemaName} = {`) {
  64. output.push('{')
  65. } else if (output.length) {
  66. if (line === '};') {
  67. output.push('}')
  68. break
  69. }
  70. output.push(line)
  71. }
  72. }
  73. return output.join("\n")
  74. }