Skip to content

Commit

Permalink
⛄ chore: support ts for rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
pdsuwwz committed Dec 21, 2021
1 parent 0d7e5cd commit 5e3eeaa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dev": "nodemon",
"watch": "babel-node src/main.ts --extensions \".ts\"",
"clean:dist": "rm -rf ./dist",
"build": "pnpm clean:dist && rollup -c",
"build": "pnpm clean:dist && rollup --c --configPlugin @rollup/plugin-typescript",
"tsbuild": "pnpm clean:dist && tsc && tsc-alias",
"start": "pm2 start ecosystem.config.js --env production",
"restart": "pm2 restart ecosystem.config.js --env production",
Expand Down Expand Up @@ -44,6 +44,7 @@
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.1",
"@rollup/plugin-typescript": "^8.3.0",
"@types/koa": "^2.13.4",
"@types/koa-bodyparser": "4.3.4",
"@types/koa-router": "^7.4.4",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RollupOptions, ModuleFormat, OutputOptions } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import { getBabelOutputPlugin } from '@rollup/plugin-babel'
import ts from 'rollup-plugin-typescript2'
Expand All @@ -8,13 +9,13 @@ import path from 'path'
const { getPresetsEnv } = require('./babel.presets')
const pkg = require(path.resolve('package.json'))

const formats = [
const formats: Array<ModuleFormat> = [
'cjs',
'esm'
]
const output = formats.map((format) => {
const output: Array<OutputOptions> = formats.map((format) => {
const fileName = `bundle.${format}.js`
return {
const result: OutputOptions = {
file: `dist/${fileName}`,
format,
banner: `
Expand All @@ -27,9 +28,10 @@ const output = formats.map((format) => {
`,
sourcemap: false
}
return result
})

export default {
const rollupConfig: RollupOptions = {
input: 'src/main.ts',
output,
external: [
Expand Down Expand Up @@ -57,3 +59,5 @@ export default {
})
]
}

export default rollupConfig
2 changes: 1 addition & 1 deletion src/services/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default class HomeService {
hello = (): Promise<unknown> => {
return new Promise(resolve => resolve({
say: {
hello: 'Hello, Koa + TypeScript',
hello: 'Hello, Puppeteer Server',
date: new Date()
}
}))
Expand Down
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"declaration": false,
"resolveJsonModule": true,
Expand All @@ -17,7 +17,7 @@
"sourceMap": false,
"outDir": "./dist",
"baseUrl": "./",
"lib": ["dom", "ES2020"],
"lib": ["dom", "esnext"],
"types": ["puppeteer", "node"],
"paths": {
"@/*": [
Expand All @@ -27,7 +27,6 @@
},
"exclude": [
"dist",
"node_modules",
"rollup.config.ts"
"node_modules"
]
}

0 comments on commit 5e3eeaa

Please sign in to comment.