Skip to content

Instantly share code, notes, and snippets.

@craftslab
Last active July 29, 2021 01:27
Show Gist options
  • Save craftslab/dd7a0534ee6496b64bc0646ffff2ab59 to your computer and use it in GitHub Desktop.
Save craftslab/dd7a0534ee6496b64bc0646ffff2ab59 to your computer and use it in GitHub Desktop.
hello vue

Install

npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890

npm install -g nrm
nrm use cnpm

Build

vue create hello-vue
cd hello-vue

npm install -g @vue/cli
npm install

npm run lint
npm run build

Run

npm run serve

Test

yarn add --dev @vue/test-utils@next
yarn add --dev jest
yarn add --dev ts-jest
yarn add --dev vue-jest@next

yarn jest --passWithNoTests

Docker

docker build -f Dockerfile -t hello-vue:latest .
docker run -it -p 8080:80 --rm --name hello-vue hello-vue:latest

Reference

<template>
<div id="app">
<VueList msg="Hello Vue"/>
</div>
</template>
<script>
import VueList from './components/VueList.vue'
export default {
name: 'App',
components: {
VueList
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN yarn install
COPY . .
RUN yarn run build
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
module.exports = {
preset: 'ts-jest',
globals: {},
testEnvironment: 'jsdom',
transform: {
"^.+\\.vue$": "vue-jest",
"^.+\\js$": "babel-jest"
},
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node']
}
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/host.access.log main;
error_log /var/log/nginx/error.log error;
gzip on;
gzip_min_length 1k;
gzip_buffers 16 64k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
<template>
<div id="vue-list">
<h1>{{ msg }}</h1>
<form v-on:submit.prevent="addNewTodo">
<label for="new-todo">Add a todo</label>
<input
v-model="newTodoText"
id="new-todo"
placeholder="E.g. Feed the cat"
>
<button>Add</button>
</form>
<ul>
<li
v-for="(todo, index) in todos"
v-bind:key="todo.id"
>
<span>{{ todo.title }}</span>
<button v-on:click="removeTodo(index)">Remove</button>
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'VueList',
props: {
msg: String
},
data: () => ({
newTodoText: '',
todos: [
{
id: 1,
title: 'Add some todos'
}
],
nextTodoId: 2
}),
methods: {
addNewTodo () {
this.todos.push({
id: this.nextTodoId++,
title: this.newTodoText.trim()
})
this.newTodoText = ''
},
removeTodo (index) {
this.todos.splice(index, 1)
}
}
}
</script>
<style scoped>
h1 {
margin: 40px 0 0;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment