├── .gitignore ├── src ├── update.js └── main.js ├── public └── index.html ├── package.json ├── rollup.config.js ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | package-lock.json 4 | public/bundle* -------------------------------------------------------------------------------- /src/update.js: -------------------------------------------------------------------------------- 1 | import format from 'date-fns/format'; 2 | 3 | var span = document.querySelector('#time-now'); 4 | 5 | export default function update() { 6 | span.textContent = format(new Date(), 'h:mm:ssa'); 7 | setTimeout(update, 1000); 8 | } 9 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import update from './update.js'; 2 | 3 | // even though Rollup is bundling all your files together, errors and 4 | // logs will still point to your original source modules 5 | console.log('if you have sourcemaps enabled in your devtools, click on main.js:5 -->'); 6 | 7 | update(); -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |The time is ...
19 | 20 | 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-starter-app", 3 | "devDependencies": { 4 | "@rollup/plugin-commonjs": "^17.0.0", 5 | "@rollup/plugin-node-resolve": "^11.1.0", 6 | "npm-run-all": "^4.1.5", 7 | "rollup": "^2.36.2", 8 | "rollup-plugin-terser": "^7.0.2", 9 | "serve": "^11.3.2" 10 | }, 11 | "dependencies": { 12 | "date-fns": "^2.16.1" 13 | }, 14 | "scripts": { 15 | "build": "rollup -c", 16 | "watch": "rollup -c -w", 17 | "dev": "npm-run-all --parallel start watch", 18 | "start": "serve public" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from '@rollup/plugin-node-resolve'; 2 | import commonjs from '@rollup/plugin-commonjs'; 3 | import { terser } from 'rollup-plugin-terser'; 4 | 5 | // `npm run build` -> `production` is true 6 | // `npm run dev` -> `production` is false 7 | const production = !process.env.ROLLUP_WATCH; 8 | 9 | export default { 10 | input: 'src/main.js', 11 | output: { 12 | file: 'public/bundle.js', 13 | format: 'iife', // immediately-invoked function expression — suitable for