diff --git a/.gitignore b/.gitignore index ca10a3c..1ba295e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ lib +esm ### https://raw.github.com/github/gitignore/4a8e0a151becd5ccbb83e4aca6e6c195f3d506fd/Global/macOS.gitignore diff --git a/package.json b/package.json index a80be29..8c61154 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,11 @@ "version": "1.0.0", "description": "Parsing Scrapbox notation with Node.js Stream", "files": [ - "lib" + "lib", + "esm" ], "main": "lib/index.js", + "module": "./esm/index.js", "types": "./lib/index.d.ts", "dependencies": { "@progfay/scrapbox-parser": "^4.0.0-0" @@ -27,8 +29,11 @@ "typescript": "^3.7.3" }, "scripts": { - "prebuild": "rm -rf lib", - "build": "tsc -p ./tsconfig.json", + "build": "npm run build:cjs && npm run build:esm", + "prebuild:cjs": "rm -rf lib", + "build:cjs": "tsc -p ./tsconfig.cjs.json", + "prebuild:esm": "rm -rf esm", + "build:esm": "tsc -p ./tsconfig.esm.json", "prepare": "npm run build", "test": "jest --coverage", "test:update": "jest --updateSnapshot", diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..86730a5 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "commonjs", + "outDir": "./lib", + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..331f74a --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "es2015", + "outDir": "./esm", + } +} diff --git a/tsconfig.json b/tsconfig.json index d5505eb..4aa0b94 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./lib", /* Redirect output structure to the directory. */ + // "outDir": "./lib", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "removeComments": true, /* Do not emit comments to output. */ @@ -37,7 +37,7 @@ "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */