Last active
January 30, 2020 05:33
-
-
Save mgdodge/f92cddda83a686bd7b9a549bb0a3e97f to your computer and use it in GitHub Desktop.
Minimal snowpack vue example
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
// File Location: babel.config.js | |
module.exports = { | |
presets: [ | |
['@babel/preset-env', { modules: false }], | |
], | |
plugins: [ | |
['snowpack/assets/babel-plugin.js', {}], | |
] | |
}; |
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
<!-- File Location: index.html --> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head><title>Snowpack - Simple Example</title></head> | |
<body> | |
<div id="app"> | |
<my-hello></my-hello> | |
</div> | |
<script type="module" src="/lib/app.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
// File Location: package.json | |
{ | |
"name": "snowpack-demo", | |
"version": "1.0.0", | |
"scripts": { | |
"prepare": "npm run transpile && snowpack --clean --include 'lib/**/*.js'", | |
"transpile": "rollup --config ./rollup.config.js" | |
}, | |
"dependencies": { | |
"vue": "^2.6.11" | |
}, | |
"devDependencies": { | |
"rollup": "^1.30.1", | |
"rollup-plugin-babel": "^4.3.3", | |
"rollup-plugin-multi-input": "^1.0.3", | |
"rollup-plugin-vue": "^5.1.6", | |
"snowpack": "^1.1.2", | |
"vue-template-compiler": "^2.6.11" | |
} | |
} |
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
// File Location: rollup.config.js | |
import vue from 'rollup-plugin-vue'; | |
import multiInput from 'rollup-plugin-multi-input'; | |
import babel from 'rollup-plugin-babel'; | |
const dest = 'web_modules/'; | |
const destRgx = new RegExp(`^.*(${dest})`); | |
export default { | |
external(id) { | |
return destRgx.test(id); | |
}, | |
input: ['src/**/*.vue', 'src/**/*.js'], | |
output: { | |
format: 'esm', | |
dir: 'lib', | |
paths(id) { | |
// Restore root-relative paths for web_modules | |
return id.replace(destRgx, '/$1'); | |
}, | |
}, | |
plugins: [ | |
multiInput(), | |
vue(), | |
babel({ | |
exclude: 'node_modules/**' // only transpile our source code | |
}), | |
] | |
} |
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
// File Location: src/app.js | |
import Vue from 'vue/dist/vue.esm.browser'; | |
import hello from './hello.vue'; | |
Vue.component('my-hello', hello); | |
new Vue({ | |
el: '#app', | |
}); |
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
<!-- File Location: src/hello.vue --> | |
<template> | |
<h1 :class="$style.h1">Hello {{ name }}</h1> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { name: 'John Doe' } | |
} | |
} | |
</script> | |
<style lang="scss" module> | |
.h1 { | |
color: red; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment