diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 7a9831588b..0000000000 --- a/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -.vs -.idea -.editorconfig -tsconfig.json -tslint.json -*.sln -src diff --git a/package.json b/package.json index 7113db334b..9d1ea5c341 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,34 @@ { "name": "@bitwarden/jslib", - "version": "0.0.10", - "scripts": { - "dev": "tsc", - "dev:watch": "tsc --watch", - "lint": "tslint src/**/*.ts || true", - "lint:fix": "tslint src/**/*.ts --fix" + "version": "0.0.11", + "description": "", + "keywords": [], + "main": "dist/index.umd.js", + "module": "dist/index.es5.js", + "typings": "dist/types/index.d.ts", + "files": [ + "dist" + ], + "license": "GPL-3.0", + "engines": { + "node": ">=6.0.0" + }, + "scripts": { + "lint": "tslint 'src/**/*.ts'", + "prebuild": "rimraf dist", + "build": "tsc && tsc --module commonjs --outDir dist/lib && rollup -c rollup.config.ts && typedoc --out dist/docs --target es6 --theme minimal --mode file src", + "start": "concurrently \"tsc -w\" \"rollup -c rollup.config.ts -w\"" }, - "main": "dist/index.js", - "types": "dist/index.d.ts", "devDependencies": { + "@types/node": "^8.0.0", + "concurrently": "^3.5.1", + "rimraf": "^2.6.2", + "rollup": "^0.53.0", + "rollup-plugin-commonjs": "^8.2.6", + "rollup-plugin-node-resolve": "^3.0.0", + "rollup-plugin-sourcemaps": "^0.4.2", "tslint": "^5.8.0", - "typescript": "^2.5.3" + "typedoc": "^0.9.0", + "typescript": "^2.6.2" } } diff --git a/rollup.config.ts b/rollup.config.ts new file mode 100644 index 0000000000..dfe12895ed --- /dev/null +++ b/rollup.config.ts @@ -0,0 +1,34 @@ +// Based upon https://github.com/alexjoverm/typescript-library-starter/blob/master/rollup.config.ts + +import commonjs from 'rollup-plugin-commonjs'; +import resolve from 'rollup-plugin-node-resolve'; +import sourceMaps from 'rollup-plugin-sourcemaps'; + +const pkg = require('./package.json'); + +const libraryName = 'index'; + +export default { + input: `dist/es/${libraryName}.js`, + output: [ + { file: pkg.main, name: libraryName, format: 'umd' }, + { file: pkg.module, format: 'es' }, + ], + sourcemap: true, + // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash') + external: [], + watch: { + include: 'dist/es/**', + }, + plugins: [ + // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) + commonjs(), + // Allow node_modules resolution, so you can use 'external' to control + // which external modules to include in the bundle + // https://github.com/rollup/rollup-plugin-node-resolve#usage + resolve(), + + // Resolve source maps to the original source + sourceMaps(), + ], +}; diff --git a/tsconfig.json b/tsconfig.json index 9f357fdd1f..0db9afbea2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,25 @@ { "compilerOptions": { - "noImplicitAny": true, - "module": "commonjs", + "moduleResolution": "node", "target": "ES2016", + "module": "es6", + "strict": true, + "sourceMap": true, "declaration": true, - "outDir": "./dist" + "allowSyntheticDefaultImports": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "declarationDir": "dist/types", + "outDir": "dist/es", + "typeRoots": [ + "node_modules/@types" + ], + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "noUnusedLocals": true, + "noUnusedParameters": true }, "include": [ - "src/**/*" + "src" ] }