Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- //package.json
- scripts: {
- "mkdir": "make-dir temp",
- "cpf": "cp -r src temp && cp server.ts temp",
- "del:temp": "rimraf temp",
- "del:dist": "rimraf dist",
- "compiler": "npm run mkdir && npm run cpf && babel --extensions '.ts' temp -d dist",
- "build": "npm run del:dist && npm run compiler && npm run del:temp"
- }
- // .babelrc
- {
- "presets": [
- ["@babel/preset-env", { "useBuiltIns": "usage", "corejs": 3, "bugfixes": true, "forceAllTransforms": true }],
- "@babel/preset-typescript"
- ],
- "plugins": [
- "@babel/plugin-transform-modules-commonjs",
- "@babel/plugin-proposal-nullish-coalescing-operator",
- "@babel/plugin-proposal-optional-chaining",
- "@babel/plugin-proposal-class-properties",
- "@babel/plugin-transform-runtime",
- "@babel/plugin-transform-destructuring",
- "@babel/plugin-transform-template-literals",
- "@babel/plugin-proposal-object-rest-spread",
- "babel-plugin-transform-remove-console",
- "babel-plugin-transform-remove-undefined",
- "babel-plugin-transform-inline-consecutive-adds",
- "babel-plugin-minify-constant-folding",
- "babel-plugin-minify-flip-comparisons",
- "babel-plugin-minify-dead-code-elimination",
- "babel-plugin-remove-unused-vars",
- "transform-merge-sibling-variables",
- "transform-remove-debugger",
- "minify-type-constructors"
- ],
- "ignore": ["node_modules", "dist", "__test__", "test"],
- "highlightCode": true,
- "sourceMaps": false,
- "comments": false
- }
- // plugin installed required
- "@babel/cli": "^7.13.10",
- "@babel/core": "^7.13.13",
- "@babel/plugin-transform-modules-commonjs": "^7.13.8",
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8",
- "@babel/plugin-transform-template-literals": "^7.13.0",
- "@babel/plugin-transform-destructuring": "^7.13.0",
- "@babel/plugin-proposal-object-rest-spread": "^7.13.8",
- "@babel/plugin-proposal-class-properties": "^7.13.0",
- "@babel/plugin-proposal-optional-chaining": "^7.13.12",
- "@babel/plugin-transform-async-to-generator": "^7.13.0",
- "@babel/plugin-transform-runtime": "^7.13.10",
- "@babel/preset-env": "^7.13.12",
- "@babel/preset-typescript": "^7.13.0",
- "@babel/runtime": "^7.13.10",
- "babel-plugin-minify-constant-folding": "^0.5.0",
- "babel-plugin-minify-dead-code-elimination": "^0.5.1",
- "babel-plugin-minify-flip-comparisons": "^0.4.3",
- "babel-plugin-minify-type-constructors": "^0.4.3",
- "babel-plugin-transform-inline-consecutive-adds": "^0.4.3",
- "babel-plugin-transform-merge-sibling-variables": "^6.9.4",
- "babel-plugin-transform-remove-console": "^6.9.4",
- "babel-plugin-remove-unused-vars": "^2.2.0",
- "babel-plugin-transform-remove-debugger": "^6.9.4",
- "babel-plugin-transform-remove-undefined": "^0.5.0",
- "core-js": "^3.9.1",
- "copyfiles": "^2.4.1",
- "typescript": "^4.1.5"
- "rimraf": "^3.0.2",
- "make-dir-cli": "^2.0.0",
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement