refactor: group asset-related files

Fixes #15
This commit is contained in:
Oliver Davies 2022-07-22 21:39:49 +01:00
parent 36d55283d2
commit 3e8421d8b7
11 changed files with 55 additions and 54 deletions

View file

@ -4,25 +4,26 @@ ARG NODE_ENV="production"
ARG SCULPIN_ENV="prod" ARG SCULPIN_ENV="prod"
ENV NODE_ENV="${NODE_ENV}" \ ENV NODE_ENV="${NODE_ENV}" \
PATH="${PATH}:/node_modules/.bin" \ PATH="${PATH}:/node_modules/.bin" \
SCULPIN_ENV="${SCULPIN_ENV}" SCULPIN_ENV="${SCULPIN_ENV}" \
USER="node"
RUN apk add --no-cache bash RUN apk add --no-cache bash
WORKDIR /app WORKDIR /app/assets
RUN mkdir -p /node_modules \ RUN mkdir -p /node_modules \
&& chown node:node -R /app /node_modules && chown node:node -R /app /node_modules
USER node USER node
COPY --chown=node:node *yarn* package.json ./ COPY --chown=node:node assets/*yarn* assets/package.json ./
RUN yarn install && yarn cache clean RUN yarn install && yarn cache clean
COPY --chown=node:node . . COPY --chown=node:node . ..
RUN if [ "${NODE_ENV}" != "development" ]; then \ RUN if [ "${NODE_ENV}" != "development" ]; then \
./run yarn:build:css && ./run yarn:build:js; \ ../run yarn:build:css && ../run yarn:build:js; \
else mkdir -p /app/build; fi else mkdir -p /app/build; fi
CMD ["bash"] CMD ["bash"]

View file

@ -0,0 +1,29 @@
const esbuild = require("esbuild");
let minify = false;
let sourcemap = true;
let watch_fs = true;
if (process.env.NODE_ENV === "production") {
minify = true;
sourcemap = false;
watch_fs = false;
}
const watch = watch_fs && {
onRebuild(error) {
if (error) console.error("[watch] build failed", error);
else console.log("[watch] build finished");
},
};
console.log(watch);
esbuild.build({
entryPoints: ["./js/app.js"],
outfile: "../source/build/app.js",
bundle: true,
minify: minify,
sourcemap: sourcemap,
watch: watch,
plugins: [],
});

View file

@ -1,20 +1,19 @@
import 'alpinejs' import "focus-visible";
import 'focus-visible' import bash from "highlight.js/lib/languages/bash";
import bash from 'highlight.js/lib/languages/bash' import hljs from "highlight.js/lib/core";
import hljs from 'highlight.js/lib/core' import ini from "highlight.js/lib/languages/ini";
import ini from 'highlight.js/lib/languages/ini' import javascript from "highlight.js/lib/languages/javascript";
import javascript from 'highlight.js/lib/languages/javascript' import php from "highlight.js/lib/languages/php";
import php from 'highlight.js/lib/languages/php' import yaml from "highlight.js/lib/languages/yaml";
import yaml from 'highlight.js/lib/languages/yaml'
hljs.registerLanguage('bash', bash); hljs.registerLanguage("bash", bash);
hljs.registerLanguage('ini', ini); hljs.registerLanguage("ini", ini);
hljs.registerLanguage('javascript', javascript); hljs.registerLanguage("javascript", javascript);
hljs.registerLanguage('php', php); hljs.registerLanguage("php", php);
hljs.registerLanguage('yaml', yaml); hljs.registerLanguage("yaml", yaml);
document.addEventListener('DOMContentLoaded', event => { document.addEventListener("DOMContentLoaded", (event) => {
document.querySelectorAll('pre code').forEach(block => { document.querySelectorAll("pre code").forEach((element) => {
hljs.highlightBlock(block) hljs.highlightElement(element);
}) });
}) });

View file

@ -13,8 +13,8 @@ x-assets: &default-assets
services: services:
css: css:
<<: *default-assets <<: *default-assets
command: "./run yarn:build:css" command: "../run yarn:build:css"
js: js:
<<: *default-assets <<: *default-assets
command: "./run yarn:build:js" command: "../run yarn:build:js"

View file

@ -1,28 +0,0 @@
const esbuild = require('esbuild')
let minify = false
let sourcemap = true
let watch_fs = true
if (process.env.NODE_ENV === 'production') {
minify = true
sourcemap = false
watch_fs = false
}
const watch = watch_fs && {
onRebuild(error) {
if (error) console.error('[watch] build failed', error)
else console.log('[watch] build finished')
},
}
esbuild.build({
entryPoints: ['./assets/js/app.js'],
outfile: './build/app.js',
bundle: true,
minify: minify,
sourcemap: sourcemap,
watch: watch,
plugins: [],
})

View file

@ -87,7 +87,7 @@ function yarn:build:css {
fi fi
tailwindcss --postcss \ tailwindcss --postcss \
-i assets/css/tailwind.pcss \ -i css/tailwind.pcss \
-o source/build/app.css "${args[@]}" -o source/build/app.css "${args[@]}"
} }