webpack.config.js 1.7 KB

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