├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .npmignore ├── .prettierrc ├── LICENSE ├── README.md ├── package.json ├── rollup.config.js ├── src └── index.tsx └── tsconfig.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/env", 4 | "@babel/typescript" 5 | ], 6 | "plugins": [ 7 | "@babel/proposal-object-rest-spread" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | max_line_length = 80 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | max_line_length = 0 14 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | node: true, 4 | browser: true, 5 | commonjs: true, 6 | es6: true 7 | }, 8 | parser: "@typescript-eslint/parser", 9 | parserOptions: { 10 | sourceType: "module", 11 | tsconfigRootDir: __dirname, 12 | createDefaultProgram: true, 13 | project: "tsconfig.json", 14 | }, 15 | plugins: ["@typescript-eslint"], 16 | rules: { 17 | "import/extensions": "off", 18 | "@typescript-eslint/explicit-function-return-type": "off" 19 | }, 20 | extends: [ 21 | "eslint:recommended", 22 | "plugin:@typescript-eslint/recommended", 23 | "plugin:@typescript-eslint/eslint-recommended", 24 | "plugin:@typescript-eslint/recommended-requiring-type-checking" 25 | ], 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Git ### 2 | # Created by git for backups. To disable backups in Git: 3 | # $ git config --global mergetool.keepBackup false 4 | *.orig 5 | 6 | # Created by git when using merge tools for conflicts 7 | *.BACKUP.* 8 | *.BASE.* 9 | *.LOCAL.* 10 | *.REMOTE.* 11 | *_BACKUP_*.txt 12 | *_BASE_*.txt 13 | *_LOCAL_*.txt 14 | *_REMOTE_*.txt 15 | 16 | ### macOS ### 17 | # General 18 | .DS_Store 19 | .AppleDouble 20 | .LSOverride 21 | 22 | # Icon must end with two \r 23 | Icon 24 | 25 | # Thumbnails 26 | ._* 27 | 28 | # Files that might appear in the root of a volume 29 | .DocumentRevisions-V100 30 | .fseventsd 31 | .Spotlight-V100 32 | .TemporaryItems 33 | .Trashes 34 | .VolumeIcon.icns 35 | .com.apple.timemachine.donotpresent 36 | 37 | # Directories potentially created on remote AFP share 38 | .AppleDB 39 | .AppleDesktop 40 | Network Trash Folder 41 | Temporary Items 42 | .apdisk 43 | 44 | ### Node ### 45 | # Logs 46 | logs 47 | *.log 48 | npm-debug.log* 49 | yarn-debug.log* 50 | yarn-error.log 51 | lerna-debug.log* 52 | 53 | # Diagnostic reports (https://nodejs.org/api/report.html) 54 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 55 | 56 | # Runtime data 57 | pids 58 | *.pid 59 | *.seed 60 | *.pid.lock 61 | 62 | # Directory for instrumented libs generated by jscoverage/JSCover 63 | lib-cov 64 | 65 | # Coverage directory used by tools like istanbul 66 | coverage 67 | *.lcov 68 | 69 | # nyc test coverage 70 | .nyc_output 71 | 72 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 73 | .grunt 74 | 75 | # Bower dependency directory (https://bower.io/) 76 | bower_components 77 | 78 | # node-waf configuration 79 | .lock-wscript 80 | 81 | # Compiled binary addons (https://nodejs.org/api/addons.html) 82 | build/Release 83 | 84 | # Dependency directories 85 | node_modules/ 86 | jspm_packages/ 87 | 88 | # TypeScript v1 declaration files 89 | typings/ 90 | 91 | # TypeScript cache 92 | *.tsbuildinfo 93 | 94 | # Optional npm cache directory 95 | .npm 96 | 97 | # Optional eslint cache 98 | .eslintcache 99 | 100 | # Optional REPL history 101 | .node_repl_history 102 | 103 | # Output of 'npm pack' 104 | *.tgz 105 | 106 | # Yarn Integrity file 107 | .yarn-integrity 108 | 109 | # dotenv environment variables file 110 | .env 111 | .env.test 112 | 113 | # parcel-bundler cache (https://parceljs.org/) 114 | .cache 115 | 116 | # next.js build output 117 | .next 118 | 119 | # nuxt.js build output 120 | .nuxt 121 | 122 | # react / gatsby 123 | public/ 124 | 125 | # vuepress build output 126 | .vuepress/dist 127 | 128 | # Serverless directories 129 | .serverless/ 130 | 131 | # FuseBox cache 132 | .fusebox/ 133 | 134 | # DynamoDB Local files 135 | .dynamodb/ 136 | 137 | ### react ### 138 | .DS_* 139 | **/*.backup.* 140 | **/*.back.* 141 | 142 | node_modules 143 | bower_componets 144 | 145 | *.sublime* 146 | 147 | psd 148 | thumb 149 | sketch 150 | 151 | ### VisualStudioCode ### 152 | .vscode/* 153 | !.vscode/settings.json 154 | !.vscode/tasks.json 155 | !.vscode/launch.json 156 | !.vscode/extensions.json 157 | 158 | ### VisualStudioCode Patch ### 159 | # Ignore all local history of files 160 | .history 161 | 162 | storybook-static 163 | dist 164 | *yarn.lock 165 | 166 | # End of https://www.gitignore.io/api/git,node,react,macos,visualstudiocode 167 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.log 2 | npm-debug.log* 3 | yarn-error.log 4 | 5 | # Dependency directories 6 | node_modules 7 | 8 | # npm package lock 9 | package-lock.json 10 | yarn.lock 11 | yarn-error.log 12 | 13 | # project files 14 | src 15 | .babelrc 16 | .editorconfig 17 | .eslintignore 18 | .eslintrc 19 | .gitignore 20 | .prettierrc 21 | rollup.config.js 22 | tsconfig.json 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "semi": true, 4 | "singleQuote": true, 5 | "trailingComma": "all", 6 | "arrowParens": "always", 7 | "tabWidth": 2, 8 | "useTabs": false 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Dmitriy D. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🐣 Rollup library starter with Typescript 2 | 3 | [![Build Status](https://travis-ci.org/toastyboost/rollup-starter.svg?branch=master)](https://travis-ci.org/toastyboost/rollup-starter) 4 | 5 | Build your library or utility into a clean, typed and cross-platform package. 6 | It's just works. Only key featurs. Updates every month. 7 | 8 | React version — 🐣[Rollup React starter with Typescript](https://github.com/toastyboost/rollup-react-starter) 9 | 10 | ## Usage 11 | 12 | `yarn build` — build an application to `dist/` 13 | `yarn lint` — lint in `src/**.ts` 14 | `yarn publish` — build an application, then publish it to NPM 15 | 16 | ## Features 17 | 18 | - [x] Bundles CJS/ES module formats 19 | - [x] ESLint plugins (not TSLint, because it's dead) 20 | - [x] Prettier 21 | - [x] Aliases 22 | - [x] Sourcemaps 23 | - [x] Autocompiling types 24 | - [x] Post clean and compression 25 | 26 | ## TODO 27 | 28 | - [ ] Test alises 29 | 30 | ## License 31 | 32 | Released under the MIT © [Dmitry D.](https://github.com/toastyboost) 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-starter", 3 | "version": "0.0.1", 4 | "main": "./dist/common.js", 5 | "module": "./dist/index.js", 6 | "types": "./dist/index.d.ts", 7 | "license": "MIT", 8 | "files": [ 9 | "dist" 10 | ], 11 | "scripts": { 12 | "build": "rm -rf dist && rollup -c", 13 | "lint": "eslint --ext .ts,.tsx src", 14 | "publish": "yarn build && yarn publish", 15 | "update": "ncu -u" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "^7.15.0", 19 | "@babel/plugin-proposal-object-rest-spread": "^7.14.7", 20 | "@babel/preset-env": "^7.15.0", 21 | "@babel/preset-typescript": "^7.15.0", 22 | "@rollup/plugin-alias": "^3.1.5", 23 | "@rollup/plugin-commonjs": "^20.0.0", 24 | "@rollup/plugin-node-resolve": "^13.0.4", 25 | "@rollup/plugin-strip": "^2.1.0", 26 | "@types/react": "^17.0.19", 27 | "@typescript-eslint/eslint-plugin": "^4.30.0", 28 | "@typescript-eslint/parser": "^4.30.0", 29 | "eslint": "^7.32.0", 30 | "eslint-plugin-prettier": "^4.0.0", 31 | "eslint-plugin-react": "^7.25.1", 32 | "prettier": "^2.3.2", 33 | "rollup": "^2.56.3", 34 | "rollup-plugin-babel": "^4.4.0", 35 | "rollup-plugin-eslint": "^7.0.0", 36 | "rollup-plugin-node-resolve": "^5.2.0", 37 | "rollup-plugin-terser": "^7.0.2", 38 | "rollup-plugin-typescript2": "^0.30.0", 39 | "typescript": "^4.4.2" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from '@rollup/plugin-node-resolve'; 2 | import commonjs from '@rollup/plugin-commonjs'; 3 | import alias from '@rollup/plugin-alias'; 4 | 5 | import babel from 'rollup-plugin-babel'; 6 | import typescript from 'rollup-plugin-typescript2'; 7 | 8 | import { eslint } from 'rollup-plugin-eslint'; 9 | import { terser } from 'rollup-plugin-terser'; 10 | 11 | import pkg from './package.json'; 12 | 13 | const extensions = ['.ts', '.tsx', '.json']; 14 | 15 | export default { 16 | input: 'src', 17 | output: [ 18 | { 19 | file: 'dist/common.js', 20 | format: 'cjs', 21 | sourcemap: true, 22 | }, 23 | { 24 | file: 'dist/index.js', 25 | format: 'esm', 26 | sourcemap: true, 27 | }, 28 | ], 29 | external: [ 30 | ...Object.keys(pkg.dependencies || {}), 31 | ...Object.keys(pkg.peerDependencies || {}), 32 | ], 33 | plugins: [ 34 | alias({ 35 | entries: { 36 | '~': './src', 37 | }, 38 | resolve: extensions, 39 | }), 40 | eslint(), 41 | typescript({ rollupCommonJSResolveHack: true, clean: true }), 42 | babel({ 43 | extensions, 44 | exclude: 'node_modules/**', 45 | }), 46 | resolve({ 47 | extensions, 48 | }), 49 | commonjs(), 50 | terser(), 51 | ], 52 | }; 53 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | type ComponentProps = { 2 | text: string; 3 | object: Record; 4 | }; 5 | 6 | export function Component({ text, object }: ComponentProps): string { 7 | const arr = { ...object, c: '3', d: '4' }; 8 | 9 | return `${text} + ${text} ${JSON.stringify(arr)}`; 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": false, 4 | "allowSyntheticDefaultImports": true, 5 | "esModuleInterop": true, 6 | "forceConsistentCasingInFileNames": true, 7 | "isolatedModules": true, 8 | "jsx": "react", 9 | "lib": [ 10 | "dom", 11 | "dom.iterable", 12 | "esnext" 13 | ], 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "noEmit": true, 17 | "resolveJsonModule": true, 18 | "skipLibCheck": true, 19 | "strict": true, 20 | "target": "es6", 21 | "declaration": true, 22 | "declarationDir": "./dist", 23 | "baseUrl": "./", 24 | "rootDir": "./src", 25 | "outDir": "./dist", 26 | "typeRoots": [ 27 | "./node_modules/@types" 28 | ], 29 | "paths": { 30 | "~/": [ 31 | "src/" 32 | ] 33 | }, 34 | }, 35 | "exclude": [ 36 | "node_modules", 37 | "dist", 38 | ], 39 | "include": [ 40 | "src" 41 | ] 42 | } 43 | --------------------------------------------------------------------------------