Giter Site home page Giter Site logo

xiaoluoboding / vue-sfc-sandbox Goto Github PK

View Code? Open in Web Editor NEW
42.0 2.0 6.0 4.94 MB

Vue SFC Sandbox, Sandbox as a Vue 3 component.

Home Page: https://vue-sfc-sandbox.vercel.app/

License: MIT License

JavaScript 7.26% HTML 15.64% Vue 55.68% TypeScript 21.41%
sandbox sfc vue3 demonstration codesandbox

vue-sfc-sandbox's Introduction

Vue SFC Sandbox

Vue SFC Sandbox, Sandbox as a Vue 3 component.


NPM NPM Download License

πŸ–ΌοΈ Preview

preview

✨ Features

πŸ—³οΈ Sandbox

  • πŸ’ͺ Fully Typed
  • πŸ“ Virtual File System (Support Compile .vue/.js File). based on vue-sfc2esm
  • πŸ‘¬ Friendly Error Tips. based on vue-sfc2esm
  • πŸ§ͺ Transpiled SFC File to ES Modules.
  • πŸ”Œ Support Externals CDN, like unpkg、jsdelivr etc.
  • 🧩 Load Import Maps as ES Modules.
  • πŸ’¨ Built-in Compile windicss on the fly, also support attributify mode.

✏️ Editor Panel

  • 🎨 Themeable Editor based on Monaco Editor
  • πŸ§‘β€πŸ’» Developer Friendly, built-in Vue 3 intellisense support
  • ↕️ REPL Sandbox with Split Panes, Split <template> & <script> tag

πŸ‘“ Preview Panel

  • ⚑️ Runtime Compile SFC File
  • πŸ” Fullscreen View
  • πŸŒ› Darkmode

πŸ’‘ Inspiration

This project is heavily inspired by Vue SFC Playground. Actually Copied from it.

πŸ“¦ Installation

yarn add vue-sfc-sandbox -S
or
npm i vue-sfc-sandbox -S

πŸ“– Usage

Notice that vue-sfc-sandbox is depending on @vue/compiler-sfc, and @vue/compiler-sfc depending on Consolidate packages. We need configure Consolidate as externals in vue.config.js or vite.config.ts file.

Demos

Vue 3 Demo: Vue CLI 3.x | Vite 2 Demo: @vitejs/app

Configure Vue 3

Add this config in vue.config.js file.

// vue.config.js in vue 3 project
module.exports = {
  ...
  configureWebpack: {
    externals: {
      consolidate: 'Consolidate'
    }
  }
  ...
}

Configure Vite 2

Add this config in vite.config.ts file.

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  define: {
    'process.env': {}
  },
  plugins: [vue()],
  optimizeDeps: {
    exclude: ['consolidate', 'velocityjs', 'dustjs-linkedin', 'atpl', 'liquor', 'twig', 'ejs', 'eco', 'jazz', 'hamljs', 'hamlet', 'jqtpl', 'whiskers', 'haml-coffee', 'hogan.js', 'templayed', 'handlebars', 'underscore', 'lodash', 'walrus', 'mustache', 'just', 'ect', 'mote', 'toffee', 'dot', 'bracket-template', 'ractive', 'htmling', 'babel-core', 'plates', 'react-dom/server', 'react', 'vash', 'slm', 'marko', 'teacup/lib/express', 'coffee-script', 'squirrelly', 'twing']
  }
})

Setup SFC Sandbox Component

// main.ts
import { createApp } from 'vue'
import App from './App.vue'

import VueSfcSandbox from 'vue-sfc-sandbox'

createApp(App)
  .use(VueSfcSandbox)
  .mount('#app')

Use SFC Sandbox Component

<template>
  <!-- [ESM] default case with <script setup> -->
  <sfc-sandbox v-bind="defaultAttrs" />
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'HelloWorld',

  setup () {
    const defaultAttrs = {
      scriptSetup: true,
      height: 200,
      sfcFilename: 'DefaultDemo.vue',
      sfcCode: `
        <template>
          <h1>{{ msg }}</h1>
        </template>

        <script setup>
        const msg = 'Hello World!'
        </script>
      `
    }

    return {
      defaultAttrs
    }
  }
})
</script>

Props

Attribute Description Type Accepted values Default
height the sandbox height unit (px) Number - 400
import-maps specify a import maps in the <script> element include type=\"importmap\" String - -
externals specify some cdn like jsdelivr、unpkg String - -
sfc-filename virtual sfc filename like HelloWorld.vue - -
sfc-code transpile sfc code to es modules by vue-sfc2esm String - -
script-setup whether script editor using <script setup> proposal Boolean true/false false

πŸ’» Development

yarn install

Compiles and hot-reloads for development

yarn serve

Compiles and minifies for production

yarn build

Lints and fixes files

yarn lint

πŸ—ƒοΈ Similar Repos

  • vuep - 🎑 A component for rendering Vue components with live editor and preview.
  • codepan - Like codepen and jsbin but works offline.
  • demosify - Create a playground to show the demos of your projects.

πŸ“„ License

MIT @xiaoluoboding

vue-sfc-sandbox's People

Contributors

xiaoluoboding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-sfc-sandbox's Issues

VE-CHART

Vue received a Component which was made a reactive object. This can lead to unnecessary performance overhead, and should be avoided by marking the component with markRaw or using shallowRef instead of ref

Support SFC?

Does this package support Vue SFC? So syntax highlighting and validation in a single .vue file? Instead of the split panes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.