Skip to content

Commit

Permalink
test: add playground
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 6, 2020
1 parent 7aaf458 commit 6490a8d
Show file tree
Hide file tree
Showing 32 changed files with 972 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
node_modules
dist
TODOs.md
playground
*.log
test/temp
42 changes: 42 additions & 0 deletions playground/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<h1>Vite Playground <code>__DEV__</code></h1>
<TestModuleResolve />
<TestHmr />
<TestPostCss />
<TestScopedCss />
<TestCssModules />
<TestPreprocessors />
<TestAssets />
<TestJsonImport />
<TestJsx />
<h2>Async Component</h2>
<TestAsync />
</template>

<script>
import { defineAsyncComponent } from "vue";
import TestModuleResolve from "./TestModuleResolve.vue";
import TestHmr from "./TestHmr.vue";
import TestPostCss from "./TestPostCss.vue";
import TestScopedCss from "./TestScopedCss.vue";
import TestCssModules from "./TestCssModules.vue";
import TestPreprocessors from "./TestPreprocessors.vue";
import TestAssets from "./TestAssets.vue";
import TestJsonImport from "./TestJsonImport.vue";
import TestJsx from "./TestJsx.vue";
export default {
components: {
TestModuleResolve,
TestHmr,
TestPostCss,
TestScopedCss,
TestCssModules,
TestPreprocessors,
TestAssets,
TestJsonImport,
TestJsx,
TestAsync: defineAsyncComponent(() => import("./TestAsync.vue")),
},
};
</script>
42 changes: 42 additions & 0 deletions playground/TestAssets.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<h2>Static Asset Handling</h2>
<p>
Fonts should be italic if font asset reference from CSS works.
</p>
<p>
Relative asset reference in template:
<img src="./testAssets.png" style="width: 30px;" />
</p>
<p>
Absolute asset reference in template:
<img src="/public/icon.png" style="width: 30px;" />
</p>
<div class="css-bg">
<span style="background:#fff">CSS background</span>
</div>
<div class="css-bg-data-uri">
<span style="background:#fff">CSS background with Data URI</span>
</div>
</template>

<style>
@font-face {
font-family: 'Inter';
font-style: italic;
font-weight: 400;
font-display: swap;
src: url("/fonts/Inter-Italic.woff2") format("woff2"),
url("./fonts/Inter-Italic.woff") format("woff");
}
body {
font-family: 'Inter';
}
.css-bg {
background: url(/public/icon.png);
background-size: 10px;
}
.css-bg-data-uri {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA0CAYAAADWr1sfAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC0wMTowOTowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NTAyNkI1RkE4N0VCMTFFQUFBQzJENzUzNDFGRjc1N0UiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NTAyNkI1Rjk4N0VCMTFFQUFBQzJENzUzNDFGRjc1N0UiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChN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+xaLrmpFRugvPcUvPltQJMUr0cXcHzjpLrF82bAHBN1O+dFTjrHTmrdjMD5vER6B/LZLQmZ3y00sytBuC65LtvLeOMt+SM+q0AmMekNNbK17G3LHsnV4Ox1QLM4wNRy3gJe2LZ88FqMbWagL8CPe2sptpXQ0/L3lsOMGcW3Cv+O+hyF+svy9pjsveWA9z0tn8Afd7F2s9lbW01GVptwJxTHZfE3/Uj17SsOU7ddLRuYsDN8decDOyorFn1sVaAvyT7k8iZNt+dke++vJ0A8+CfMw+3mT8s39HtBviSgDs+b+64zF26HQHz+C/o+Xmfn5c5ul0BXyT7w/U5oTdlbs1GQGs/vgb9cd7fazr+L8AAD0zRYMSYHQAAAAAASUVORK5CYII=);
background-size: 10px;
}
</style>
3 changes: 3 additions & 0 deletions playground/TestAsync.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>This should show up...</div>
</template>
21 changes: 21 additions & 0 deletions playground/TestCssModules.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<h2>CSS Modules</h2>
<div :class="$style.blue">&lt;style module&gt; - this should be blue</div>
<div :class="imported.turquoise">
CSS modules import - this should be orange
</div>
</template>

<script>
import imported from "./testCssModules.module.css";
export default {
data: () => ({ imported }),
};
</script>

<style module>
.blue {
color: blue;
}
</style>
35 changes: 35 additions & 0 deletions playground/TestHmr.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<h2>Hot Module Replacement</h2>
<p>
<span>
HMR: click button and edit template part of <code>./TestHmr.vue</code>,
count should not reset
</span>
<button @click="count++">&gt;&gt;&gt; {{ count }} &lt;&lt;&lt;</button>
</p>
<p>
<span>
HMR: edit the return value of <code>foo()</code> in
<code>./testHmrPropagation.js</code>, should update without reloading
page:
</span>
<span>{{ foo() }}</span>
</p>
<p>
HMR: manual API (see console) - edit <code>./testHmrManual.js</code> and it
should log new exported value without reloading the page.
</p>
</template>

<script>
import { foo } from "./testHmrPropagation";
export default {
setup() {
return {
count: 0,
foo,
};
},
};
</script>
11 changes: 11 additions & 0 deletions playground/TestJsonImport.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<pre>Imported JSON: {{ json }}</pre>
</template>

<script>
import json from './testJsonImport.json'
export default {
data: () => ({ json })
}
</script>
23 changes: 23 additions & 0 deletions playground/TestJsx.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div>
<h2>JSX</h2>
<div ref="root"></div>
</div>
</template>

<script>
import { ref, onMounted } from 'vue'
import { renderPreact } from './testJsx.jsx'
export default {
setup() {
const root = ref()
onMounted(() => {
renderPreact(root.value)
})
return { root }
}
}
</script>
31 changes: 31 additions & 0 deletions playground/TestModuleResolve.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<h2>Module Resolving</h2>
<div :class="router">vue-router@next {{ router }}</div>
<div :class="store">vuex@next {{ store }}</div>
<div :class="web_modules">web_modules {{ web_modules }}</div>
</template>

<script>
import { createRouter } from "vue-router";
import { createStore } from "vuex";
import { dep } from "web-modules-dep";
export default {
setup() {
return {
router: typeof createRouter === "function" ? "ok" : "error",
store: typeof createStore === "function" ? "ok" : "error",
web_modules: dep() ? "ok" : "error",
};
},
};
</script>

<style scoped>
.ok {
color: green;
}
.error {
color: red;
}
</style>
22 changes: 22 additions & 0 deletions playground/TestPostCss.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<h2>PostCSS</h2>
<div class="postcss-from-css">
CSS import with PostCSS: This should be red
</div>
<div class="postcss-from-sfc">
&lt;style&gt; with PostCSS: This should be green
</div>
</template>

<script>
import './testPostCss.css'
export default {}
</script>

<style>
body {
& .postcss-from-sfc {
color: green;
}
}
</style>
14 changes: 14 additions & 0 deletions playground/TestPreprocessors.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template lang="pug">
h2 Pre-Processors
p.hello
| This is rendered from &lt;template lang="pug"&gt;
| and styled with &lt;style lang="sass"&gt;. It should be megenta.
</template>

<style lang="scss">
$color: magenta;
.hello {
color: $color;
}
</style>
10 changes: 10 additions & 0 deletions playground/TestScopedCss.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<h2>Scoped CSS</h2>
<div>&lt;style scoped&gt;: only this should be purple</div>
</template>

<style scoped>
div {
color: #8A2BE2;
}
</style>
20 changes: 20 additions & 0 deletions playground/TestTs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template lang="pug">
p {{ count }} {{ msg }}
p
button(@click='count++') increment
</template>

<script lang="ts">
import { foo } from './util'
const log = (foo: string) => foo + Date.now()
export default {
setup() {
return {
count: 0,
msg: foo() + log('ok!')
}
}
}
</script>
Binary file added playground/fonts/Inter-Italic.woff
Binary file not shown.
Binary file added playground/fonts/Inter-Italic.woff2
Binary file not shown.
3 changes: 3 additions & 0 deletions playground/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<link rel="icon" href="/public/icon.png" />
<div id="app"></div>
<script type="module" src="./main.js"></script>
5 changes: 5 additions & 0 deletions playground/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createApp } from 'vue'
import App from './App.vue'
import './testHmrManual'

createApp(App).mount('#app')
17 changes: 17 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"scripts": {
"dev": "DEBUG=vite:* vite --jsx-factory=h",
"build": "DEBUG=vite:* vite build --jsx-factory=h",
"serve": "serve dist"
},
"dependencies": {
"preact": "^10.4.1",
"vue-router": "^4.0.0-alpha.9",
"vuex": "^4.0.0-beta.1"
},
"devDependencies": {
"postcss-nesting": "^7.0.1",
"pug": "^2.0.4",
"sass": "^1.26.3"
}
}
3 changes: 3 additions & 0 deletions playground/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: [require('postcss-nesting')]
}
Binary file added playground/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions playground/testAssets.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@font-face {
font-family: 'Inter';
font-style: italic;
font-weight: 400;
font-display: swap;
src: url("fonts/Inter-Italic.woff2") format("woff2"),
url("fonts/Inter-Italic.woff") format("woff");
}
Binary file added playground/testAssets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions playground/testCssModules.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.turquoise {
color: #FF8C00;
}
9 changes: 9 additions & 0 deletions playground/testHmrManual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { hot } from '@hmr'

export const foo = 1

if (__DEV__) {
hot.accept(({ foo }) => {
console.log('foo is now: ', foo)
})
}
3 changes: 3 additions & 0 deletions playground/testHmrPropagation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function foo() {
return 1
}
3 changes: 3 additions & 0 deletions playground/testJsonImport.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "this is json"
}
11 changes: 11 additions & 0 deletions playground/testJsx.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { h, render } from 'preact'
import { Test } from './testTsx.tsx'

const Component = () => <div>
Rendered from Preact JSX
<Test count={1337} />
</div>

export function renderPreact(el) {
render(h(Component), el)
}
6 changes: 6 additions & 0 deletions playground/testPostCss.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* postcss-nesting */
body {
& .postcss-from-css {
color: red;
}
}
6 changes: 6 additions & 0 deletions playground/testTsImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { baz } from './baz.js'

export function foo(m: string) {
console.log('you crazy' + m)
return baz() + 'yo crazy'
}
5 changes: 5 additions & 0 deletions playground/testTsx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { h } from 'preact'

export function Test(props: { count: 0 }) {
return <div>Rendered from TSX: count is {props.count}</div>
}
3 changes: 3 additions & 0 deletions playground/web_modules/web-modules-dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function dep() {
return __DEV__
}
Loading

0 comments on commit 6490a8d

Please sign in to comment.