- Use lebab to convert your modules to ES2015 modules.
lebab es5.js -o es6.js --transform commonjs
- Change the
.js
extensions to .ts
.
- Install typescript as a devDependency to your package
npm i -D typescript
- Add a
tsconfig.json
to the root of your package with the following content:
{
"compilerOptions": {
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"declaration": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"strictNullChecks": true,
"target": "es6",
"outDir": "dist",
"module": "commonjs",
"moduleResolution": "node"
},
"filesGlob": [
"src/"
]
}
- Add a prepublish script task to your
package.json
:
{
...
"scripts": {
...
"prepublish": "tsc",
...
},
...
}