Compile all images under resources/images into assets/images using vite build co...liberu-genealogy/genealogy-laravel#291
![Logo of Sweep](/_next/image?url=%2Flogo.png&w=64&q=75)
Compile all images under resources/images into assets/images using vite build co...
liberu-genealogy/genealogy-laravel#291
> > >
✓ Completed in 6 minutes, 4 months ago using GPT-4  •  Book a call  •  Report a bug
Progress
  ModifyChanged
vite.config.jsÂ
Changed vite.config.js
in b43b5ce
   Â
1 | import { defineConfig } from 'vite' | 1 | import { defineConfig } from 'vite' |
2 | import laravel, { refreshPaths } from 'laravel-vite-plugin' | 2 | import { defineConfig } from 'vite'; |
3 | import laravel, { refreshPaths } from 'laravel-vite-plugin'; | ||
4 | import path from 'path'; | ||
5 | import copy from 'vite-plugin-copy'; | ||
3 | 6 | ||
4 | export default defineConfig({ | 7 | export default defineConfig({ |
5 | plugins: [ | 8 | plugins: [ |
6 | laravel({ | ||
7 | input: ['resources/css/app.css', 'resources/js/app.js'], | ||
8 | refresh: [ | ||
9 | ...refreshPaths, | ||
10 | 'app/Filament/**', | ||
11 | 'app/Forms/Components/**', | ||
12 | 'app/Livewire/**', | ||
13 | 'app/Infolists/Components/**', | ||
14 | 'app/Providers/Filament/**', | ||
15 | 'app/Tables/Columns/**', | ||
16 | ], | ||
17 | }), | 9 | laravel(['resources/css/app.css', 'resources/js/app.js']), |
10 | copy({ | ||
11 | targets: [ | ||
12 | { src: 'resources/images/*', dest: 'public/assets/images' } | ||
13 | ], | ||
14 | resolve: { | ||
15 | alias: { | ||
16 | '@': path.resolve(__dirname, './resources') | ||
17 | } | ||
18 | }, | ||
19 | hook: 'writeBundle' // Use the 'writeBundle' hook to copy files after the bundle is written | ||
20 | }), | ||
18 | ], | 21 | ], |
19 | }) | 22 | }) |
- Start by importing the necessary modules at the top of the file:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import path from 'path';
- Next, configure the Vite build process to include the copying of images from
resources/images
toassets/images
. Since Vite itself does not provide a built-in way to copy files as part of the build process, you can use thevite-plugin-copy
plugin to achieve this. First, you need to install the plugin by runningnpm install vite-plugin-copy --save-dev
. - After installing the plugin, modify the
vite.config.js
to include the plugin configuration:
import copy from 'vite-plugin-copy';
export default defineConfig({
plugins: [
laravel(['resources/css/app.css', 'resources/js/app.js']),
copy({
targets: [
{ src: 'resources/images/*', dest: 'public/assets/images' }
],
hook: 'writeBundle' // Use the 'writeBundle' hook to copy files after the bundle is written
})
],
resolve: {
alias: {
'@': path.resolve(__dirname, './resources')
}
}
});
- This configuration uses the
vite-plugin-copy
to copy all files fromresources/images
topublic/assets/images
during the build process. Thehook: 'writeBundle'
option ensures that the copying occurs after the bundle has been written to disk.
Modified file with Assistant API
  Run GitHub Actions for
vite.config.jsÂ
Ran GitHub Actions for b43b5ce2a8111f0a59978f61757fa8abf354c28f:
  Modify
package.json:4-5Â
4 "scripts": {
5 "dev": "vite",
- Ensure the
build
script inpackage.json
references the Vite configuration correctly to include the image processing step. No changes are strictly necessary here, but verify that thebuild
script looks like this:
"build": "vite build"
- This ensures that when
npm run build
is executed, Vite uses the configuration specified invite.config.js
, which now includes the image copying logic.
Modifying file with Assistant API
  Run GitHub Actions for
package.jsonÂ
Plan
This is based on the results of the Planning step. The plan may expand from failed GitHub Actions runs.
  Modify
vite.config.jsÂ
  Run GitHub Actions for
vite.config.jsÂ
  Modify
package.json:4-5Â
  Run GitHub Actions for
package.jsonÂ
Code Snippets Found
This is based on the results of the Searching step.
Dockerfile:0-162
 1# Accepted values: 8.3 - 8.2
2ARG PHP_VERSION=8.3
3
4ARG COMPOSER_VERSION=latest
5
6###########################################
7# Build frontend assets with NPM
8###########################################
9
10ARG NODE_VERSION=20-alpine
11
12FROM node:${NODE_VERSION} AS build
13
14ENV ROOT=/var/www/html
15
16WORKDIR ${ROOT}
17
18RUN npm config set update-notifier false && npm set progress=false
19
20COPY package*.json ./
21
22RUN if [ -f $ROOT/package-lock.json ]; \
23 then \
24 npm ci --loglevel=error --no-audit; \
25 else \
26 npm install --loglevel=error --no-audit; \
27 fi
28
29COPY . .
30
31RUN npm run build
32
33###########################################
34
35FROM composer:${COMPOSER_VERSION} AS vendor
36
37FROM php:${PHP_VERSION}-cli-bookworm AS base
38
39LABEL maintainer="Curtis Delicat <curtis.delicata@liberu.co.uk"
40LABEL org.opencontainers.image.title="Liberu Genealogy Dockerfile"
41LABEL org.opencontainers.image.description="Production-ready Dockerfile for Liberu Genealogy"
42LABEL org.opencontainers.image.source=https://github.com/liberu-genealogy/genealogy-laravel
43LABEL org.opencontainers.image.licenses=MIT
44
45ARG WWWUSER=1000
46ARG WWWGROUP=1000
47ARG TZ=UTC
48
49ENV DEBIAN_FRONTEND=noninteractive \
50 TERM=xterm-color \
51 WITH_HORIZON=false \
52 WITH_SCHEDULER=false \
53 OCTANE_SERVER=swoole \
54 USER=octane \
55 ROOT=/var/www/html \
56 COMPOSER_FUND=0 \
57 COMPOSER_MAX_PARALLEL_HTTP=24
58
59WORKDIR ${ROOT}
60
61SHELL ["/bin/bash", "-eou", "pipefail", "-c"]
62
63RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
64 && echo ${TZ} > /etc/timezone
65
66ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
67
68RUN apt-get update; \
69 apt-get upgrade -yqq; \
70 apt-get install -yqq --no-install-recommends --show-progress \
71 apt-utils \
72 curl \
73 wget \
74 nano \
75 ncdu \
76 ca-certificates \
77 supervisor \
78 libsodium-dev \
79 # Install PHP extensions
80 && install-php-extensions \
81 bz2 \
82 pcntl \
83 mbstring \
84 bcmath \
85 sockets \
86 pgsql \
87 pdo_pgsql \
88 opcache \
89 exif \
90 pdo_mysql \
91 zip \
92 intl \
93 gd \
94 redis \
95 rdkafka \
96 memcached \
97 igbinary \
98 ldap \
99 swoole \
100 && apt-get -y autoremove \
101 && apt-get clean \
102 && docker-php-source delete \
103 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
104 && rm /var/log/lastlog /var/log/faillog
105
106RUN wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64" \
107 -O /usr/bin/supercronic \
108 && chmod +x /usr/bin/supercronic \
109 && mkdir -p /etc/supercronic \
110 && echo "*/1 * * * * php ${ROOT}/artisan schedule:run --verbose --no-interaction" > /etc/supercronic/laravel
111
112RUN userdel --remove --force www-data \
113 && groupadd --force -g ${WWWGROUP} ${USER} \
114 && useradd -ms /bin/bash --no-log-init --no-user-group -g ${WWWGROUP} -u ${WWWUSER} ${USER}
115
116RUN chown -R ${USER}:${USER} ${ROOT} /var/{log,run} \
117 && chmod -R a+rw /var/{log,run}
118
119RUN cp ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini
120
121USER ${USER}
122
123COPY --chown=${USER}:${USER} --from=vendor /usr/bin/composer /usr/bin/composer
124COPY --chown=${USER}:${USER} composer.json composer.lock ./
125
126RUN composer install \
127 --no-dev \
128 --no-interaction \
129 --no-autoloader \
130 --no-ansi \
131 --no-scripts \
132 --audit
133
134COPY --chown=${USER}:${USER} . .
135COPY --chown=${USER}:${USER} --from=build ${ROOT}/public public
136
137RUN mkdir -p \
138 storage/framework/{sessions,views,cache,testing} \
139 storage/logs \
140 bootstrap/cache && chmod -R a+rw storage
141
142COPY --chown=${USER}:${USER} .docker/octane/Swoole/supervisord.swoole.conf /etc/supervisor/conf.d/
143COPY --chown=${USER}:${USER} .docker/supervisord.*.conf /etc/supervisor/conf.d/
144COPY --chown=${USER}:${USER} .docker/php.ini ${PHP_INI_DIR}/conf.d/99-octane.ini
145COPY --chown=${USER}:${USER} .docker/start-container /usr/local/bin/start-container
146
147RUN composer install \
148 --classmap-authoritative \
149 --no-interaction \
150 --no-ansi \
151 --no-dev \
152 && composer clear-cache \
153 && php artisan storage:link
154
155RUN chmod +x /usr/local/bin/start-container
156
157RUN cat .docker/utilities.sh >> ~/.bashrc
158
159EXPOSE 80
160
161ENTRYPOINT ["start-container"]
162
package.json:0-22
 1{
2 "type": "module",
3 "private": true,
4 "scripts": {
5 "dev": "vite",
6 "build": "vite build"
7 },
8 "devDependencies": {
9 "@tailwindcss/forms": "^0.5.7",
10 "@tailwindcss/typography": "^0.5.10",
11 "autoprefixer": "^10.4.18",
12 "laravel-vite-plugin": "^1.0.2",
13 "postcss": "^8.4.35",
14 "postcss-nesting": "^12.1.0",
15
16
17
18
19 "tailwindcss": "^3.5.2",
20 "vite": "^5.2.0"
21
22 }