Last active
March 28, 2020 11:32
-
-
Save motine/544af1e7da5d1bbede74e93d1d265ede to your computer and use it in GitHub Desktop.
Rollup multi page bundles
This file contains 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
body { font-family: mono; } |
This file contains 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
<template> | |
<div class="hello">Hello {{ name }}.</div> | |
</template> | |
<script> | |
export default { | |
data() { return { name: 'Manfred' } } | |
} | |
</script> | |
<style scoped> | |
.hello { color: tomato; } | |
</style> |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<div id="app"></div> | |
<link rel="stylesheet" type="text/css" href="dist/main.css" /> | |
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script> | |
<script src="dist/page1.js"></script> | |
</body> | |
</html> |
This file contains 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 Vue from "vue/dist/vue.esm.browser.js"; | |
import Hello from "./components/Hello.vue"; | |
import './base.css'; | |
new Vue({ | |
el: "#app", | |
template: "<hello/>", | |
components: { Hello } | |
}); |
This file contains 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 Vue from "vue/dist/vue.esm.browser.js"; | |
import './base.css'; | |
new Vue({ | |
el: "#app", | |
template: "<div>other</div>" | |
}); |
This file contains 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 vue from "rollup-plugin-vue"; | |
// import resolve from "@rollup/plugin-node-resolve"; | |
import { terser } from "rollup-plugin-terser"; | |
import css from 'rollup-plugin-css-only' | |
import babel from 'rollup-plugin-babel'; | |
const isProduction = process.env.NODE_ENV === 'production'; | |
const defaultPlugins = [ | |
vue({ compileTemplate: true, css: false }), | |
css({ output: 'dist/main.css' }), | |
babel({ exclude: 'node_modules/**' }), | |
isProduction && terser() // minify | |
]; | |
export default [ | |
{ | |
input: "src/page1.js", | |
output: { file: "dist/page1.js", format: 'iife' }, | |
plugins: defaultPlugins | |
}, | |
{ | |
input: "src/page2.js", | |
output: { file: "dist/page2.js", format: 'iife' }, | |
plugins: defaultPlugins | |
}, | |
]; | |
// this will generate: | |
// dist/base-abc234.js | |
// dist/main.css | |
// dist/page1.js (this includes an import to base-abc234.js) | |
// dist/page2.js (this includes an import to base-abc234.js) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment