Last active
January 14, 2019 23:50
-
-
Save baetheus/edbc6851bdf5e7ac46a3dfd677872716 to your computer and use it in GitHub Desktop.
Rollup + Typescript + Serve + Preact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import del from 'rollup-plugin-delete'; | |
| import typescript from 'rollup-plugin-typescript'; | |
| import resolve from 'rollup-plugin-node-resolve'; | |
| import commonjs from 'rollup-plugin-commonjs'; | |
| import htmlTemplate from 'rollup-plugin-generate-html-template'; | |
| import copy from 'rollup-plugin-copy'; | |
| import serve from 'rollup-plugin-serve'; | |
| import { terser } from 'rollup-plugin-terser'; | |
| const createHash = () => | |
| Math.random() | |
| .toString(36) | |
| .slice(2, 7); | |
| const tryThen = (fn, then) => { | |
| try { | |
| return fn(); | |
| } catch { | |
| return then; | |
| } | |
| }; | |
| const ENV = tryThen(() => process.env.NODE_ENV || 'development', 'development'); | |
| const runServe = ENV !== 'production'; | |
| export default { | |
| // Entrypoint | |
| input: './src/main.tsx', | |
| // Output | |
| output: { | |
| file: `dist/bundle-${createHash()}.js`, | |
| format: 'iife', | |
| name: 'main', | |
| sourcemap: true, | |
| }, | |
| // Workflow | |
| plugins: [ | |
| // Clear previous dist | |
| del({ targets: 'dist/*' }), | |
| // Compile away typescript types | |
| typescript(), | |
| // Resolve node imports | |
| resolve({ browser: true }), | |
| // Turn commonjs bundles into es2015 bundles | |
| commonjs(), | |
| // Minify js | |
| terser(), | |
| // Seed index.html with the build script | |
| htmlTemplate({ | |
| template: 'src/template.html', | |
| target: 'index.html', | |
| }), | |
| // Copy assets to dist | |
| copy({ | |
| 'src/assets': 'dist/assets', | |
| }), | |
| ].concat( | |
| // Serve the build when not production | |
| runServe | |
| ? serve({ | |
| contentBase: 'dist', | |
| port: 1234, | |
| headers: { | |
| 'Access-Control-Allow-Origin': '*', | |
| }, | |
| }) | |
| : [] | |
| ), | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
| { | |
| "compilerOptions": { | |
| "strict": true, | |
| "strictFunctionTypes": true, | |
| "strictNullChecks": true, | |
| "strictPropertyInitialization": true, | |
| "allowUnreachableCode": false, | |
| "noImplicitAny": true, | |
| "noErrorTruncation": true, | |
| "alwaysStrict": true, | |
| "noUnusedLocals": true, | |
| "noUnusedParameters": true, | |
| "skipLibCheck": true, | |
| "esModuleInterop": true, | |
| "sourceMap": true, | |
| "lib": ["es5", "es6", "dom"], | |
| "types": ["node"], | |
| "jsx": "react", | |
| "jsxFactory": "h", | |
| "baseUrl": "./", | |
| "paths": { | |
| "~/*": ["./src/*"] | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment