Advertisement
aldikhan13

TRANSFORMATION NODE TYPESCRIPT CODE TO PRODUCTION CODE

Mar 27th, 2021 (edited)
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. Recommended for production using Nodejs Typescript, use Babel as an additional feature of the compiler and many plugins can be used, because the default Typescript compiler cannot be used to delete console.log for your production code if you imagine there are 100 console.log entered into different files. after dev development, it will be homework if you have to remove them one by one, try this method for production code Nodejs + Typecript.
  2.  
  3. //package.json
  4. scripts: {
  5. "mkdir": "make-dir temp",
  6. "cpf": "cp -r src temp && cp server.ts temp",
  7. "del:temp": "rimraf temp",
  8. "del:dist": "rimraf dist",
  9. "compiler": "npm run mkdir && npm run cpf && babel --extensions '.ts' temp -d dist",
  10. "build": "npm run del:dist && npm run compiler && npm run del:temp"
  11. }
  12.  
  13. // .babelrc
  14. {
  15. "presets": [
  16. ["@babel/preset-env", { "useBuiltIns": "usage", "corejs": 3, "bugfixes": true, "forceAllTransforms": true }],
  17. "@babel/preset-typescript"
  18. ],
  19. "plugins": [
  20. "@babel/plugin-transform-modules-commonjs",
  21. "@babel/plugin-proposal-nullish-coalescing-operator",
  22. "@babel/plugin-proposal-optional-chaining",
  23. "@babel/plugin-proposal-class-properties",
  24. "@babel/plugin-transform-runtime",
  25. "@babel/plugin-transform-destructuring",
  26. "@babel/plugin-transform-template-literals",
  27. "@babel/plugin-proposal-object-rest-spread",
  28. "babel-plugin-transform-remove-console",
  29. "babel-plugin-transform-remove-undefined",
  30. "babel-plugin-transform-inline-consecutive-adds",
  31. "babel-plugin-minify-constant-folding",
  32. "babel-plugin-minify-flip-comparisons",
  33. "babel-plugin-minify-dead-code-elimination",
  34. "babel-plugin-remove-unused-vars",
  35. "transform-merge-sibling-variables",
  36. "transform-remove-debugger",
  37. "minify-type-constructors"
  38. ],
  39. "ignore": ["node_modules", "dist", "__test__", "test"],
  40. "highlightCode": true,
  41. "sourceMaps": false,
  42. "comments": false
  43. }
  44.  
  45. // plugin installed required
  46.  
  47. "@babel/cli": "^7.13.10",
  48. "@babel/core": "^7.13.13",
  49. "@babel/plugin-transform-modules-commonjs": "^7.13.8",
  50. "@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8",
  51. "@babel/plugin-transform-template-literals": "^7.13.0",
  52. "@babel/plugin-transform-destructuring": "^7.13.0",
  53. "@babel/plugin-proposal-object-rest-spread": "^7.13.8",
  54. "@babel/plugin-proposal-class-properties": "^7.13.0",
  55. "@babel/plugin-proposal-optional-chaining": "^7.13.12",
  56. "@babel/plugin-transform-async-to-generator": "^7.13.0",
  57. "@babel/plugin-transform-runtime": "^7.13.10",
  58. "@babel/preset-env": "^7.13.12",
  59. "@babel/preset-typescript": "^7.13.0",
  60. "@babel/runtime": "^7.13.10",
  61. "babel-plugin-minify-constant-folding": "^0.5.0",
  62. "babel-plugin-minify-dead-code-elimination": "^0.5.1",
  63. "babel-plugin-minify-flip-comparisons": "^0.4.3",
  64. "babel-plugin-minify-type-constructors": "^0.4.3",
  65. "babel-plugin-transform-inline-consecutive-adds": "^0.4.3",
  66. "babel-plugin-transform-merge-sibling-variables": "^6.9.4",
  67. "babel-plugin-transform-remove-console": "^6.9.4",
  68. "babel-plugin-remove-unused-vars": "^2.2.0",
  69. "babel-plugin-transform-remove-debugger": "^6.9.4",
  70. "babel-plugin-transform-remove-undefined": "^0.5.0",
  71. "core-js": "^3.9.1",
  72. "copyfiles": "^2.4.1",
  73. "typescript": "^4.1.5"
  74. "rimraf": "^3.0.2",
  75. "make-dir-cli": "^2.0.0",
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement