1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vue-dev-serverを試してみる

Posted at

vue-dev-serverとは

Imagine you can import Vue single-file components natively in your browser... without a build step.

ビルドすることなく、ブラウザから直接 Vue の Single File Component を インポートすることができる模様

早速使ってみる

使い方は Github の README に書かれているので、そのとおりに進めてみる

vuejs/vue-dev-server

インストール

今回はサクッと試したいのでグローバルインストール

$ npm i -g @vue/dev-server

index.html.vue ファイルを準備する

適当な作業ディレクトリを作る

$ mkdir vue-dev-server-sample
$ cd vue-dev-server-sample

index.html を作成する

vue-dev-server-sample/index.html
<!DOCTYPE html>
<html>
  <head>
    <title>vue-dev-server-sample</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module">
    // CDN から直接 Vue をインポートする
    import Vue from 'https://unpkg.com/vue/dist/vue.esm.browser.js'
    import App from './App.vue'
    
    new Vue({
      render: h => h(App)
    }).$mount('#app')
    </script>
  </body>
</html>

続いて、おなじみの Single File Componentを準備する

vue-dev-server-sample/App.vue
<template>
  <div>
    <h1>{{ msg }}</h1>
  </div>
</template>

<script>
export default {
  data () {
    return {
      msg: 'Hello from Vue SFC without any build !!'
    }
  }
}
</script>

<style scoped>
h1 {
  text-align: center;
  color: #42b983;
}
</style>

サーバーを起動する

$ npx vue-dev-server
server running at http://localhost:3000

image.png

まとめ

  • ビルド無し、ブラウザのみでお手軽に Vue の SFC を試せる
  • まだ概念実証(Proof of Concept)の段階なので、あくまでお試し感覚でどうぞ
  • どのように動いているか興味のある人は Githubリポジトリ
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?