├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | package-lock.json -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # rollup-plugin-sucrase changelog 2 | 3 | ## 2.1.0 4 | 5 | * Add `filter` option ([#4](https://github.com/rollup/rollup-plugin-sucrase/pull/4)) 6 | * Remove lockfile so we always get most recent version of Sucrase 7 | * Resolve extensionless imports ([#3](https://github.com/rollup/rollup-plugin-sucrase/issues/3)) 8 | 9 | ## 2.0.0 10 | 11 | * Update to Sucrase 3.x ([#2](https://github.com/rollup/rollup-plugin-sucrase/pull/2)) 12 | 13 | ## 1.0.0 14 | 15 | * First release -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Rich Harris 2 | 3 | Permission is hereby granted by the authors of this software, to any person, to use the software for any purpose, free of charge, including the rights to run, read, copy, change, distribute and sell it, and including usage rights to any patents the authors may hold on it, subject to the following conditions: 4 | 5 | This license, or a link to its text, must be included with all copies of the software and any derivative works. 6 | 7 | Any modification to the software submitted to the authors may be incorporated into the software under the terms of this license. 8 | 9 | The software is provided "as is", without warranty of any kind, including but not limited to the warranties of title, fitness, merchantability and non-infringement. The authors have no obligation to provide support or updates for the software, and may not be held liable for any damages, claims or other liability arising from its use. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Moved 2 | 3 | This package has moved and is now available at [@rollup/plugin-sucrase](https://github.com/rollup/plugins). Please update your dependencies. This repository is no longer maintained. 4 | 5 | 6 | # rollup-plugin-sucrase 7 | 8 | Use [Sucrase](https://github.com/alangpierce/sucrase) with Rollup. 9 | 10 | ## Installation 11 | 12 | ```bash 13 | yarn add -D rollup-plugin-sucrase 14 | ``` 15 | 16 | 17 | ### Usage 18 | 19 | An example of compiling TypeScript (the node-resolve plugin is added to automatically add file extensions, since TypeScript expects not to find them): 20 | 21 | ```js 22 | // rollup.config.js 23 | import sucrase from 'rollup-plugin-sucrase'; 24 | import resolve from 'rollup-plugin-node-resolve'; 25 | 26 | export default { 27 | input: 'src/index.ts', 28 | output: { 29 | file: 'dist/bundle.js', 30 | format: 'cjs' 31 | }, 32 | plugins: [ 33 | resolve({ 34 | extensions: ['.js', '.ts' ] 35 | }), 36 | sucrase({ 37 | exclude: ['node_modules/**'], 38 | transforms: ['typescript'] 39 | }) 40 | ] 41 | } 42 | ``` 43 | 44 | 45 | ## License 46 | 47 | [LIL](LICENSE). 48 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const { transform } = require('sucrase'); 4 | const { createFilter } = require('rollup-pluginutils'); 5 | 6 | module.exports = function sucrase(opts = {}) { 7 | const filter = createFilter(opts.include, opts.exclude); 8 | 9 | return { 10 | name: 'sucrase', 11 | 12 | resolveId(importee, importer) { 13 | if (importer && importee[0] === '.') { 14 | const resolved = path.resolve( 15 | (importer ? path.dirname(importer) : process.cwd()), 16 | importee 17 | ); 18 | 19 | if (!fs.existsSync(resolved) && fs.existsSync(resolved + '.ts')) { 20 | return resolved + '.ts'; 21 | } 22 | } 23 | }, 24 | 25 | transform(code, id) { 26 | if (!filter(id)) return null; 27 | 28 | const result = transform(code, { 29 | transforms: opts.transforms, 30 | jsxPragma: opts.jsxPragma, 31 | jsxFragmentPragma: opts.jsxFragmentPragma, 32 | enableLegacyTypeScriptModuleInterop: 33 | opts.enableLegacyTypeScriptModuleInterop, 34 | enableLegacyBabel5ModuleInterop: 35 | opts.enableLegacyTypeScriptModuleInterop, 36 | production: opts.production, 37 | filePath: id, 38 | sourceMapOptions: { 39 | compiledFilename: id, 40 | } 41 | }); 42 | return { 43 | code: result.code, 44 | map: result.sourceMap, 45 | } 46 | }, 47 | }; 48 | }; 49 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-plugin-sucrase", 3 | "version": "2.1.0", 4 | "dependencies": { 5 | "rollup-pluginutils": "^2.3.0", 6 | "sucrase": "3.x" 7 | }, 8 | "description": "Compile TypeScript, Flow, JSX etc with Sucrase", 9 | "main": "index.js", 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/rollup/rollup-plugin-sucrase.git" 17 | }, 18 | "keywords": [ 19 | "sucrase", 20 | "typescript", 21 | "flow", 22 | "jsx", 23 | "rollup" 24 | ], 25 | "author": "Rich Harris", 26 | "license": "LIL", 27 | "bugs": { 28 | "url": "https://github.com/rollup/rollup-plugin-sucrase/issues" 29 | }, 30 | "homepage": "https://github.com/rollup/rollup-plugin-sucrase#readme" 31 | } 32 | --------------------------------------------------------------------------------