lustre-labs / dev-tools

Lustre's CLI and development tooling: zero-config dev server, bundling, and scaffolding.
41 stars 15 forks source link

How to use index.html with `build app` #42

Open lpil opened 3 months ago

lpil commented 3 months ago

Hello!

I'm trying to deploy my application but I'm having a problem where I don't know how to get the index.html file for the compiled application.

The build command doesn't move it to the priv static directory, and if you use the --minify flag Lustre writes the output files to a different location than normal so you can't copy it directly across.

What's the right way to do this?

Thanks, Louis

stewartrule commented 2 months ago

Was wondering the same thing. As a workaround I've added the build artifacts to my .gitignore and added a small shell script (build_gh.sh) that builds the app, copies the index.html to the /priv/static/ folder, and then updates the paths.

gleam run -m lustre/dev build app --minify

cp ./index.html ./priv/static/index.html

sed -i 's/app\.css/app\.min\.css/' ./priv/static/index.html
sed -i 's/app\.mjs/app\.min\.mjs/' ./priv/static/index.html
sed -i 's/\/priv\/static/\./' ./priv/static/index.html

And added that as an extra build step before deploying to gh-pages:

jobs:
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - uses: erlef/setup-beam@v1
        with:
          otp-version: '26.0.2'
          gleam-version: '1.2.1'
          rebar3-version: '3'
      - run: gleam deps download
      - name: Setup Pages
        uses: actions/configure-pages@v5
      - name: Build
        run: ./build_gh.sh
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: './priv/static/'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4