Skip to content

Commit

Permalink
Merge pull request #8 from pdsuwwz/chore/babel-typescript
Browse files Browse the repository at this point in the history
chore(rollup, nodemon): use babel plugin & preset env
  • Loading branch information
pdsuwwz authored Jul 14, 2021
2 parents dbceaea + 54cf5bb commit b1ec9fe
Show file tree
Hide file tree
Showing 7 changed files with 1,506 additions and 21 deletions.
22 changes: 22 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Configuration for development environment only
*/

const { getPresetsEnv } = require('./babel.presets')

module.exports = {
presets: [
getPresetsEnv(),
'@babel/preset-typescript'
],
plugins: [
[
'module-resolver',
{
alias: {
'@': './src'
}
}
]
]
}
13 changes: 13 additions & 0 deletions babel.presets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
getPresetsEnv (isModule = true) {
return [
'@babel/preset-env', {
targets: {
node: '10.18.1'
},
// https://github.com/babel/babel/issues/10374#issuecomment-597029696
modules: isModule ? 'auto' : false
}
]
}
}
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"restartable": "rs",
"watch": ["src"],
"ext": "ts",
"exec": "ts-node -r tsconfig-paths/register --transpile-only src/main.ts"
"exec": "yarn watch"
}
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"scripts": {
"dev": "nodemon",
"watch": "babel-node src/main.ts --extensions \".ts\"",
"clean:dist": "rm -rf ./dist",
"build": "yarn clean:dist && rollup -c",
"tsbuild": "yarn clean:dist && tsc && tsc-alias",
Expand All @@ -34,6 +35,11 @@
"puppeteer": "^10.1.0"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/node": "^7.14.7",
"@babel/preset-env": "^7.14.7",
"@babel/preset-typescript": "^7.14.5",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
Expand All @@ -43,6 +49,7 @@
"@types/node": "^15.12.5",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"babel-plugin-module-resolver": "^4.1.0",
"conventional-changelog-cli": "^2.1.1",
"eslint": "^7.29.0",
"nodemon": "^2.0.7",
Expand All @@ -62,6 +69,7 @@
"pm2",
"nodemon",
"eslint",
"rollup"
"rollup",
"babel"
]
}
36 changes: 28 additions & 8 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { getBabelOutputPlugin } from '@rollup/plugin-babel'
import ts from 'rollup-plugin-typescript2'
import json from '@rollup/plugin-json'

import commonjs from '@rollup/plugin-commonjs'
import path from 'path'

const { getPresetsEnv } = require('./babel.presets')
const pkg = require(path.resolve('package.json'))

const formats = [
'cjs',
'esm'
]
const output = formats.map((format) => ({
file: `dist/bundle.${format}.js`,
format,
sourcemap: false
}))
const output = formats.map((format) => {
const fileName = `bundle.${format}.js`
return {
file: `dist/${fileName}`,
format,
banner: `
/**
* @license
* author: ${pkg.author}
* ${fileName} v${pkg.version}
* Released under the ${pkg.license} license.
*/
`,
sourcemap: false
}
})

export default {
input: 'src/main.ts',
Expand All @@ -25,6 +38,11 @@ export default {
...['path', 'url', 'os', 'stream']
],
plugins: [
getBabelOutputPlugin({
presets: [
getPresetsEnv(false)
]
}),
nodeResolve(),
json(),
ts({
Expand All @@ -34,6 +52,8 @@ export default {
}
}
}),
commonjs({ extensions: ['.js', '.ts'] })
commonjs({
extensions: ['.js', '.ts']
})
]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"resolveJsonModule": true,
"esModuleInterop": true,
"noImplicitAny": true,
// "noEmit": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"suppressImplicitAnyIndexErrors": true,
"removeComments": true,
Expand All @@ -28,5 +30,4 @@
"node_modules",
"rollup.config.ts"
]
// "include": ["ormconfig.json"]
}
Loading

0 comments on commit b1ec9fe

Please sign in to comment.