-
-
Save frank-dspeed/ea412e8cca42853dc26aa2603703a40b to your computer and use it in GitHub Desktop.
rollup with typescript
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
{ | |
"name": "topz2", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"couch:start": "docker run -p 5984:5984 -it -v $(pwd)/couchdata:/opt/couchdb/data -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=local_development_password topzcouch" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"prettier": { | |
"trailingComma": "all", | |
"useTabs": true | |
}, | |
"dependencies": { | |
"aws-sdk": "^2.636.0", | |
"body-parser": "^1.19.0", | |
"dotenv": "^8.2.0", | |
"fast-proxy": "^1.4.1", | |
"got": "^10.6.0", | |
"jsonwebtoken": "^8.5.1", | |
"nano": "^8.2.2", | |
"restana": "^4.0.8" | |
}, | |
"devDependencies": { | |
"@babel/core": "^7.8.7", | |
"@babel/plugin-transform-react-jsx": "^7.8.3", | |
"@babel/preset-modules": "^0.1.3", | |
"@babel/preset-typescript": "^7.8.3", | |
"@rollup/plugin-commonjs": "^11.0.2", | |
"@rollup/plugin-html": "^0.1.1", | |
"@rollup/plugin-node-resolve": "^7.1.1", | |
"@rollup/plugin-typescript": "^4.0.0", | |
"@typescript-eslint/eslint-plugin": "^2.23.0", | |
"@typescript-eslint/parser": "^2.23.0", | |
"eslint": "^6.8.0", | |
"eslint-config-prettier": "^6.10.0", | |
"jest": "^25.1.0", | |
"node-sass": "^4.13.1", | |
"pouchdb": "^7.2.1", | |
"pouchdb-find": "^7.2.1", | |
"preact": "^10.3.4", | |
"prettier": "^1.19.1", | |
"prettier-plugin-svelte": "^0.7.0", | |
"rollup": "^2.0.2", | |
"rollup-plugin-babel": "^4.4.0", | |
"rollup-plugin-node-builtins": "^2.1.2", | |
"rollup-plugin-node-globals": "^1.4.0", | |
"rollup-plugin-postcss": "^2.4.1", | |
"rollup-plugin-svelte": "^5.1.1", | |
"rollup-plugin-terser": "^5.3.0", | |
"serve-static": "^1.14.1", | |
"svelte": "^3.19.2", | |
"svelte-material-ui": "^1.0.0-beta.20", | |
"typescript": "^3.8.3" | |
} | |
} |
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 html from "@rollup/plugin-html"; | |
import resolve from "@rollup/plugin-node-resolve"; | |
import { join } from "path"; | |
import babel from "rollup-plugin-babel"; | |
import nodeBultins from "rollup-plugin-node-builtins"; | |
import nodeGlobals from "rollup-plugin-node-globals"; | |
import postcss from "rollup-plugin-postcss"; | |
import commonjs from "@rollup/plugin-commonjs"; | |
import svelte from "rollup-plugin-svelte"; | |
import { terser } from "rollup-plugin-terser"; | |
import files from "serve-static"; | |
const production = !process.env.ROLLUP_WATCH; | |
if (!production) { | |
const { server } = require("./dist/server"); | |
console.log(server); | |
server.use(files(join(__dirname, "dist", "client"))); | |
} | |
const extensions = [".js", ".jsx", ".ts", ".tsx", ".json", ".mjs"]; | |
const distDir = "dist/client"; | |
const plugins = (...args) => [ | |
svelte({ dev: !production }), | |
resolve({ | |
browser: true, | |
extensions, | |
preferBuiltins: true, | |
dedupe: ["svelte"], | |
}), | |
commonjs(), | |
nodeBultins(), | |
nodeGlobals(), | |
babel({ | |
extensions, | |
include: ["src/*", "src/**/*"], | |
presets: ["@babel/preset-typescript", "@babel/preset-modules"], | |
}), | |
...args, | |
production && terser({ output: { comments: false } }), | |
]; | |
export default [ | |
{ | |
input: "./src/index.ts", | |
plugins: plugins( | |
postcss({ | |
extensions: [".scss", ".sass"], | |
extract: false, | |
minimize: true, | |
use: [ | |
[ | |
"sass", | |
{ | |
includePaths: ["./src/", "./node_modules"], | |
}, | |
], | |
], | |
}), | |
html({ | |
template, | |
}), | |
), | |
output: { | |
dir: distDir, | |
format: "esm", | |
sourcemap: true, | |
}, | |
}, | |
{ | |
input: "./src/data/worker.ts", | |
plugins: plugins(), | |
globals: { | |
global: "self", | |
}, | |
output: { | |
dir: distDir, | |
format: "iife", | |
sourcemap: true, | |
}, | |
}, | |
]; | |
function template({ attributes, bundle, files, publicPath, title }) { | |
const scripts = files.js | |
.map( | |
({ fileName }) => | |
`<script type="module" src="${fileName}" defer></script>`, | |
) | |
.join("\n"); | |
const styles = [ | |
{ fileName: "https://fonts.googleapis.com/icon?family=Material+Icons" }, | |
{ | |
fileName: | |
"https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700", | |
}, | |
{ fileName: "https://fonts.googleapis.com/css?family=Roboto+Mono" }, | |
] | |
.concat(files.css || []) | |
.map(({ fileName }) => `<link rel="stylesheet" href="${fileName}">`) | |
.join("\n"); | |
return `<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Topz</title> | |
${styles} | |
</head> | |
<body> | |
${scripts} | |
</body> | |
</html>`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment