Skip to content

Commit ef3d6fc

Browse files
authored
Add in Rollup Example App (#5)
Adds in a very simple Rollup from their example starter.
1 parent a380ebb commit ef3d6fc

File tree

7 files changed

+729
-70
lines changed

7 files changed

+729
-70
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const config = {
88
"plugin:@typescript-eslint/stylistic-type-checked",
99
"plugin:prettier/recommended",
1010
],
11+
ignorePatterns: ["**/bundlers/**"],
1112
parserOptions: {
1213
ecmaVersion: "latest",
1314
sourceType: "module",
1415
tsconfigRootDir: __dirname,
1516
project: [
1617
"./tsconfig.json",
1718
"./packages/bundler-plugin-core/tsconfig.json",
18-
"./packages/esbuild-plugin/tsconfig.json",
1919
"./packages/rollup-plugin/tsconfig.json",
2020
"./packages/vite-plugin/tsconfig.json",
2121
"./packages/webpack-plugin/tsconfig.json",

bundlers/rollup/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "rollup",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "rollup -c",
8+
"watch": "rollup -c -w",
9+
"dev": "npm-run-all --parallel start watch",
10+
"start": "serve public"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"date-fns": "^2.16.1"
17+
},
18+
"devDependencies": {
19+
"@rollup/plugin-commonjs": "^17.0.0",
20+
"@rollup/plugin-node-resolve": "^11.1.0",
21+
"npm-run-all": "^4.1.5",
22+
"rollup": "^2.36.2",
23+
"rollup-plugin-terser": "^7.0.2",
24+
"serve": "^11.3.2"
25+
},
26+
"volta": {
27+
"extends": "../../package.json"
28+
},
29+
"engines": {
30+
"node": ">=20.0.0"
31+
}
32+
}

bundlers/rollup/public/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width" />
6+
<title>rollup-starter-app</title>
7+
8+
<style>
9+
body {
10+
font-family: "Helvetica Neue", Arial, sans-serif;
11+
color: #333;
12+
font-weight: 300;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<h1>rollup-starter-app</h1>
18+
<p>The time is <span id="time-now">...</span></p>
19+
<script src="bundle.js"></script>
20+
</body>
21+
</html>

bundlers/rollup/rollup.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
dir: 'dist',
13+
format: "iife", // immediately-invoked function expression — suitable for <script> tags
14+
sourcemap: true,
15+
16+
},
17+
plugins: [
18+
resolve(), // tells Rollup how to find date-fns in node_modules
19+
commonjs(), // converts date-fns to ES modules
20+
production && terser(), // minify, but only in production
21+
],
22+
};

bundlers/rollup/src/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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(
6+
"if you have sourcemaps enabled in your devtools, click on main.js:5 -->",
7+
);
8+
9+
update();

bundlers/rollup/src/update.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

0 commit comments

Comments
 (0)