Skip to content

Commit d617940

Browse files
author
Sebastian Boolean
committed
adding README, update generator
1 parent 2630abb commit d617940

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# vue-cli-plugin-docker-nginx
2+
3+
> vue-cli-plugin that adds a minimal docker deployment using a nginx server to serve your static files
4+
5+
## Installation
6+
7+
```
8+
vue add vue-cli-plygin-docker-nginx
9+
```
10+
11+
This will automatically add all the files needed to your existing vue-cli project
12+
13+
### Build and run local docker container
14+
15+
```
16+
npm run docker
17+
```
18+
19+
This will build a docker container and run it on a free port. Please make sure to have [docker](https://docs.docker.com/install/) installed and running on your machine.
20+
21+
### Tweak nginx config
22+
23+
With the default settings nginx listens on port `80` and is configured to route all requests back to `index.html`. This way you can safely use `history`-mode in your `vue-router`. These settings can be changed in `default.conf` in you projects root.

generator.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = api => {
2-
api.extendPackage({
3-
scripts: {
4-
'docker': 'docker build . -t app && docker run -d -p 8080:8080 app'
5-
}
6-
})
7-
api.render('./template')
8-
}
2+
api.extendPackage({
3+
scripts: {
4+
docker: 'docker build . -t vue-app && docker run -d -p:80 vue-app',
5+
},
6+
});
7+
api.render('./template');
8+
};

template/Dockerfile

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
FROM node:alpine
2-
RUN mkdir -p /usr/src/app
1+
# stage-1: build dist folder
2+
FROM node:alpine as build
33
WORKDIR /usr/src/app
44
COPY ["package.json", "package-lock.json", "/usr/src/app/"]
5-
RUN npm install
6-
COPY . /usr/src/app
5+
RUN npm install --silent
6+
COPY . .
77
RUN npm run build
88

9+
# stage-2: copy static files to nginx image
910
FROM nginx:alpine
1011
EXPOSE 80
1112
COPY default.conf /etc/nginx/conf.d/default.conf
12-
COPY --from=0 /usr/src/app/dist /usr/share/nginx/html
13+
COPY --from=build /usr/src/app/dist /usr/share/nginx/html

0 commit comments

Comments
 (0)