Jonathan Scheiber

Build assets with Webpack Encore and Gitlab CI

Read time: one minute No comments
Build assets with Webpack Encore and Gitlab CI

In the previous article I detailed how to build assets with Webpack Encore on Github Actions. But how to achieve the same using Gitlab CI?

Build assets using Github Actions was not really easy at first. However, with Gitlab CI, the configuration for the same result is a little more straight forward:

image: node:14.3-alpine

cache:
  paths:
  - node_modules/

before_script:
  - yarn install

build:
  script:
  - ./node_modules/.bin/encore production
  artifacts:
    name: "assets"
    paths:
    - public/build/

Some explanations

The build is based on a nodejs Docker image (here, version 14.3). The CI is configured to cache the node_modules directory, then run the yarn install command to retrieve up-to-date dependencies.

After that, it executes Encore in production mode in order to have the assets in a compressed format.

Finally, an assets artifact is created with the build content, which is present in the public/build directory.

Et voilà! Your Gitlab CI can now build your assets with Webpack Encore :)

If you have any remarks, questions, suggestions... about this article, feel free to comment it, any feedback is welcome :)

Comments

There are no comments. Be the first to comment!

Add a comment