Skip to content

Instantly share code, notes, and snippets.

@bcherny
Last active January 30, 2024 12:13
Show Gist options
  • Star 54 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bcherny/eb11719f9fbe6b01412da7c64feb44c3 to your computer and use it in GitHub Desktop.
Save bcherny/eb11719f9fbe6b01412da7c64feb44c3 to your computer and use it in GitHub Desktop.
react + rollup + typescript boilerplate

terminal:

npm i --save-dev rollup rollup-watch rollup-plugin-typescript typescript typings
npm i -S react react-dom
./node_modules/.bin/typings install react react-dom --save
mkdir src dist
touch src/index.tsx

package.json:

"scripts": {
  "build": "rollup -c",
  "watch": "rollup -cw"
}

rollup.config.js:

import typescript from 'rollup-plugin-typescript'

export default {
  entry: './src/index.tsx',
  dest: './dist/bundle.js',
  format: 'iife',
  plugins: [
    typescript()
  ]
}

tsconfig.json:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "module": "es6",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "outDir": "./dist",
    "preserveConstEnums": true,
    "target": "es5"
  },
  "exclude": [
    "node_modules"
  ]
}
@krokofant
Copy link

Thanks! This was helpful in getting up and running. Simple and elegant 👍

@krokofant
Copy link

What is the point of installing typescript? rollup uses the one that comes with rollup-plugin-typescript which is 1.8.9 as of now.

@SeanJM
Copy link

SeanJM commented Oct 18, 2016

There's a new version of TypeScript (2.0), another reason for installing it is so you can specify the local installation of 2.0.

@mattd-rs
Copy link

This doesn't work out of the box anymore due to new versions of these packages. Consider adding version numbers of what will work.

@rek
Copy link

rek commented Sep 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment