Skip to content

Commit

Permalink
Switching to Vite for UI Dev (#924)
Browse files Browse the repository at this point in the history
* WIP

* Get bulma and fontawesome to work

* Fix sass division warnings

* Rm .vue extensions

* Restore ui folder back to main

* setup proxy

* Get Jest working

* eslint and prettier configs

* prettier ignore

* Rm old ui dir

* Fix build

* Support proxying config via env vars

* Add filter func

* README updates; run vite on 8081

* Cleanup

* Fix Dockerfile
  • Loading branch information
markphelps authored Jul 5, 2022
1 parent ed07fea commit 6cb4025
Show file tree
Hide file tree
Showing 67 changed files with 24,211 additions and 32,041 deletions.
34 changes: 20 additions & 14 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The `bootstrap` task will install all of the necessary tools used for developmen
Configuration for running when developing Flipt can be found at `./config/local.yml`. To run Flipt with this configuration, run:

```shell
task dev
task server
```

## Changes
Expand All @@ -55,30 +55,36 @@ Running `task assets` will regenerate the embedded assets (ui, api documentation

#### UI components

The UI is built using [NPM](https://nodejs.org/en/) and [webpack](https://webpack.js.org/) and is also statically compiled into the Flipt binary.
The UI is built using [NPM](https://nodejs.org/en/) and [Vite](https://vitejs.dev/) and is also statically compiled into the Flipt binary.

The [ui/README.md](https://github.com/markphelps/flipt/tree/main/ui/README.md) has more information on how to build the UI and also how to run it locally during development.

## Remote Containers/GitHub Codespaces
## Building/Running

Flipt now supports [VSCode Remote Containers](https://github.com/Microsoft/vscode-dev-containers)/[GitHub Codespaces](https://github.com/features/codespaces).
**Run `script/server` from the project root.**

These technologies allow you to quickly get setup with a Flipt development environment either locally or 'in the cloud'.
Vite will rebuild the UI assets when applicable files in the `ui` folder change. See [ui/README.md](https://github.com/markphelps/flipt/tree/main/ui/README.md) for more info.

For VSCode Remote Containers (devcontainers), make sure you have [Docker](https://www.docker.com/get-started) and the [ms-vscode-remote.remote-containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed. Then simply clone this repo, open it in VSCode and run the [`Remote-Containers: Open Folder in Container`](https://code.visualstudio.com/docs/remote/containers#_quick-start-open-an-existing-folder-in-a-container) command in VSCode.
You'll need to stop and re-run `script/server` for any changes in the server (Go) code :exclamation:

If you have access to [GitHub Codespaces](https://github.com/features/codespaces), simply open Flipt in a codespaces from the `Code` tab in the repo on GitHub or click the button below.
### Ports

[![Open in Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new/?repo=markphelps/flipt)
In development, the three ports that Flipt users are:

- `8080`: The port for the Flipt REST API
- `8081`: The port for the Flipt UI (via `npm run dev`)
- `9000`: The port for the Flipt GRPC Server

### Building/Running
These three ports will be forwarded to your local machine automatically if you are developing Flipt in a VSCode Remote Container or GitHub Codespace.

Run `script/server` from the project root.
## Remote Containers/GitHub Codespaces

The `webpack-dev-server` that is used when running the UI in development mode will rebuild the UI assets when applicable files in the `ui` folder change. See [ui/README.md](https://github.com/markphelps/flipt/tree/main/ui/README.md) for more info.
Flipt now supports [VSCode Remote Containers](https://github.com/Microsoft/vscode-dev-containers)/[GitHub Codespaces](https://github.com/features/codespaces).

### Ports
These technologies allow you to quickly get setup with a Flipt development environment either locally or 'in the cloud'.

The three ports `8080`, `8081`, `9000` will be forwarded to your local machine automatically.
For VSCode Remote Containers (devcontainers), make sure you have [Docker](https://www.docker.com/get-started) and the [ms-vscode-remote.remote-containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed. Then simply clone this repo, open it in VSCode and run the [`Remote-Containers: Open Folder in Container`](https://code.visualstudio.com/docs/remote/containers#_quick-start-open-an-existing-folder-in-a-container) command in VSCode.

If you have access to [GitHub Codespaces](https://github.com/features/codespaces), simply open Flipt in a codespaces from the `Code` tab in the repo on GitHub or click the button below.

`8081` is the UI dev port that runs the `npm dev server` that you can open in your browser.
[![Open in Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new/?repo=markphelps/flipt)
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN apt-get update && \
RUN curl -sSL https://deb.nodesource.com/setup_18.x | bash && \
apt-get update && \
apt-get install -y --no-install-recommends \
nodejs \
nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Expand Down
34 changes: 17 additions & 17 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version: 3
vars:
PROJECT: flipt
SOURCE_FILES: ./...
UI: ui

tasks:
default:
Expand All @@ -20,29 +21,28 @@ tasks:
assets:
desc: Build the UI
deps: [assets:deps]
dir: "{{.UI}}"
cmds:
- cd ui && npm run build
env:
NODE_OPTIONS: --openssl-legacy-provider
- npm run build
sources:
- ./ui/static/*
- ./ui/src/**/*
- ./ui/src/**/**/*
- ./ui/index.html
- ./ui/package.json
- ./{{.UI}}/static/*
- ./{{.UI}}/src/**/*
- ./{{.UI}}/src/**/**/*
- ./{{.UI}}/index.html
- ./{{.UI}}/package.json
method: checksum

assets:deps:
desc: Install UI dependencies
dir: "{{.UI}}"
cmds:
- cd ui && npm ci
env:
NODE_OPTIONS: --openssl-legacy-provider
- npm ci

assets:dev:
desc: Run the UI dev server
dir: "{{.UI}}"
cmds:
- cd ui && npm run dev
- npm run dev

bench:
desc: Run benchmarks
Expand Down Expand Up @@ -92,6 +92,11 @@ tasks:
cmds:
- buf generate

server:
desc: Start the server
cmds:
- go run ./cmd/flipt/. --config ./config/local.yml --force-migrate

clean:
desc: Remove built assets
cmds:
Expand All @@ -107,11 +112,6 @@ tasks:
vars:
COVERAGE_FILE: coverage.txt

dev:
desc: Start the server
cmds:
- go run ./cmd/flipt/. --config ./config/local.yml --force-migrate

fmt:
desc: Run goimports
cmds:
Expand Down
2 changes: 1 addition & 1 deletion script/server
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -euo pipefail

task --parallel dev assets:dev
task --parallel server assets:dev
37 changes: 0 additions & 37 deletions ui/.babelrc

This file was deleted.

4 changes: 0 additions & 4 deletions ui/.eslintignore

This file was deleted.

4 changes: 1 addition & 3 deletions ui/.eslintrc.cjs → ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

module.exports = {
root: true,
parserOptions: {
parser: "babel-eslint",
},
env: {
browser: true,
node: true,
Expand Down Expand Up @@ -42,6 +39,7 @@ module.exports = {
ignores: ["draggable"],
},
],
"vue/no-reserved-component-names": "off",
"vue/multi-word-component-names": "off",
"no-async-promise-executor": "off",
"no-misleading-character-class": "off",
Expand Down
17 changes: 14 additions & 3 deletions ui/.gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
.DS_Store
node_modules/
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.vscode
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
/test-results/
/playwright-report/
/playwright/.cache/
5 changes: 0 additions & 5 deletions ui/.postcssrc.yml

This file was deleted.

4 changes: 3 additions & 1 deletion ui/.prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist/
dist/
src/assets/
README.md
1 change: 0 additions & 1 deletion ui/.tool-versions

This file was deleted.

5 changes: 4 additions & 1 deletion ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

The Flipt UI uses the [Vue.js](https://vuejs.org/) framework to build a modern single page application.

The ui directory contains these `.vue` files, along with others used in the web UI. These source files are built and packed together into simple HTML, JS, and CSS assets. For easier distribution these assets are statically compiled into the Flipt binary using the [go/embed](https://golang.org/pkg/embed/) package.
This directory contains these `.vue` files, along with others used in the web UI. These source files are built and packed together into simple HTML, JS, and CSS assets using the [Vite](https://vitejs.dev/) build tool.

For easier distribution these assets are then statically compiled into the Flipt binary using the [go/embed](https://golang.org/pkg/embed/) package.

## Build Requirements

- [NodeJS >= 18](https://nodejs.org/en/)
- [Go >= 1.17](https://golang.org/doc/install/source.html)
3 changes: 3 additions & 0 deletions ui/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
45 changes: 0 additions & 45 deletions ui/build/build.js

This file was deleted.

Loading

0 comments on commit 6cb4025

Please sign in to comment.