Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Skip registering compile hooks #462

Merged
merged 3 commits into from
Jan 23, 2024

Conversation

Basster
Copy link
Contributor

@Basster Basster commented Jul 18, 2023

I'm deploying my application via Docker and do Docker multi-stage build (builder-pattern) to build my frontend stuff. This looks a little bit like this:

Excerpt:

FROM composer AS composer

# install composer packages

FROM php AS php

COPY --from=composer --chown=root:www-data /app/vendor /app/vendor
COPY --chown=root:www-data . /app

RUN set -eux; \
    php bin/console assets:install; \
    php bin/console fos:js-routing:dump --format json --target assets/fos_js_routes.json;

# [...] configure php base layer

FROM node:16-alpine AS node

COPY package.json yarn.lock webpack.config.js postcss.config.js .babelrc /build/
COPY assets /build/assets
COPY public /build/public
COPY --from=php /app/public/bundles /build/public/bundles
COPY --from=php /app/assets/fos_js_routes.json /build/assets/fos_js_routes.json
COPY --from=php /app/vendor/friendsofsymfony/jsrouting-bundle /build/vendor/friendsofsymfony/jsrouting-bundle

RUN 
    set -eux; \
    yarn --pure-lockfile;  \
    yarn build;

# [...] more frontend stuff...

FROM php AS prod

# Copy frontend files.
COPY --from=node --chown=root:www-data /build/public/build /app/public/build

# [...] finalize the image

This way I avoid having composer and node in my runtime image.

Today I wanted to try the FosRouting webpack plugin and noticed, that tries to build the fos_js_routes.json during webpack build/watch, wich is pretty convenient, but didn't fit into my build process, since I don't have PHP available during yarn build.

So I decided to add an optional parameter to the FoRouting plugin, to disable registering the compile hooks, so the plugin uses the existing, statically dumped fos_js_routes.json during runtime.

// webpack.config.js

Encore
        .addPlugin(new FosRouting(
            { target: './assets/fos_js_routes.json' }, // <- path to dumped routes.json 
            false // <- set false to suppress automatic recompilation of the file
            )
        )

This way you can compile the finalTarget e.g. in a separate process and don't need php during compile time.
@tobias-93 tobias-93 merged commit 42422c8 into FriendsOfSymfony:master Jan 23, 2024
9 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants