Begin work on nix deployment logic for vite
This commit is contained in:
parent
6f677b5638
commit
d52101d25b
4 changed files with 36 additions and 38 deletions
63
default.nix
63
default.nix
|
|
@ -27,54 +27,51 @@ pkgs.buildGoModule rec {
|
|||
pkgs.nodejs
|
||||
];
|
||||
|
||||
pnpmDeps = pnpmDeps;
|
||||
pnpmDeps = pkgs.pnpm.fetchDeps {
|
||||
fetcherVersion = 2;
|
||||
hash = "sha256-UvE49UmVw8zVFHywxRWyzL0EiZvuZjmm9hA1U98o2sA=";
|
||||
pname = "nidus-sync-frontend";
|
||||
src = ./.;
|
||||
version = "0.0.11";
|
||||
};
|
||||
|
||||
preBuild = ''
|
||||
# Setup node_modules from pnpm dependencies
|
||||
export HOME=$(mktemp -d)
|
||||
pnpm config set store-dir $HOME/.pnpm-store
|
||||
|
||||
# Compile SCSS
|
||||
SASS_SRC_DIR="./scss"
|
||||
GEN_OUTPUT_DIR="./static/gen"
|
||||
# Icon generation
|
||||
mkdir -p "./ts/gen"
|
||||
pnpm generate-icons
|
||||
|
||||
mkdir -p "$GEN_OUTPUT_DIR"
|
||||
# Remove static links
|
||||
# Build frontend
|
||||
pnpm build-rmo
|
||||
pnpm build-sync
|
||||
cp vite/rmo/index.html static/gen/rmo/index.html
|
||||
cp vite/sync/index.html static/gen/sync/index.html
|
||||
|
||||
echo "Compiling $SASS_SRC_DIR/style.scss to $GEN_OUTPUT_DIR/main.css..."
|
||||
sass --style=compressed --trace "$SASS_SRC_DIR/style.scss":"$GEN_OUTPUT_DIR/main.css"
|
||||
# Extract the hash from bundle.[hash].js
|
||||
RMO_BUNDLE_FILE=$(ls vite/rmo/static/gen/js/bundle.*.js | grep -v '.map$' | head -n1)
|
||||
RMO_BUNDLE_HASH=$(basename "$RMO_BUNDLE_FILE" | sed 's/bundle\.\(.*\)\.js/\1/')
|
||||
SYNC_BUNDLE_FILE=$(ls vite/sync/static/gen/js/bundle.*.js | grep -v '.map$' | head -n1)
|
||||
SYNC_BUNDLE_HASH=$(basename "$SYNC_BUNDLE_FILE" | sed 's/bundle\.\(.*\)\.js/\1/')
|
||||
|
||||
# Generate hash and rename style
|
||||
STYLE_HASH=$(sha256sum "$GEN_OUTPUT_DIR/main.css" | cut -c1-12)
|
||||
mv "$GEN_OUTPUT_DIR/main.css" "$GEN_OUTPUT_DIR/style.$STYLE_HASH.css"
|
||||
echo "Generated CSS style with hash: $STYLE_HASH"
|
||||
|
||||
# Bundle TypeScript
|
||||
GEN_OUTPUT_DIR="./static/gen"
|
||||
mkdir -p "$GEN_OUTPUT_DIR"
|
||||
|
||||
echo "Bundling TypeScript with Vue..."
|
||||
esbuild ts/main.ts \
|
||||
--bundle \
|
||||
--minify \
|
||||
--format=esm \
|
||||
--define:__VUE_OPTIONS_API__=true \
|
||||
--define:__VUE_PROD_DEVTOOLS__=false \
|
||||
--define:__VUE_PROD_HYDRATION_MISMATCH_DETAILS__=false \
|
||||
--alias:vue=vue/dist/vue.esm-bundler.js \
|
||||
--outfile="$GEN_OUTPUT_DIR/main.js"
|
||||
|
||||
# Generate hash and rename bundle
|
||||
BUNDLE_HASH=$(sha256sum "$GEN_OUTPUT_DIR/main.js" | cut -c1-12)
|
||||
mv "$GEN_OUTPUT_DIR/main.js" "$GEN_OUTPUT_DIR/bundle.$BUNDLE_HASH.js"
|
||||
echo "Generated JS bundle with hash: $BUNDLE_HASH"
|
||||
# Extract the hash from style.[hash].css
|
||||
RMO_STYLE_FILE=$(ls vite/rmo/static/gen/css/style.*.css | head -n1)
|
||||
RMO_STYLE_HASH=$(basename "$RMO_STYLE_FILE" | sed 's/style\.\(.*\)\.css/\1/')
|
||||
SYNC_STYLE_FILE=$(ls vite/sync/static/gen/css/style.*.css | head -n1)
|
||||
SYNC_STYLE_HASH=$(basename "$SYNC_STYLE_FILE" | sed 's/style\.\(.*\)\.css/\1/')
|
||||
|
||||
# Generate gen.go with bundle path
|
||||
cat > static/gen.go <<EOF
|
||||
package static
|
||||
|
||||
// Generated by Nix build - do not edit manually
|
||||
const BundlePathCSS = "/static/gen/css/style.$STYLE_HASH.css"
|
||||
const BundlePathJS = "/static/gen/js/bundle.$BUNDLE_HASH.js"
|
||||
const BundlePathRMOCSS = "/static/gen/css/style.$STYLE_HASH.css"
|
||||
const BundlePathRMOJS = "/static/gen/js/bundle.$BUNDLE_HASH.js"
|
||||
const BundlePathSyncCSS = "/static/gen/css/style.$STYLE_HASH.css"
|
||||
const BundlePathSyncJS = "/static/gen/js/bundle.$BUNDLE_HASH.js"
|
||||
EOF
|
||||
echo "Generated static/gen.go"
|
||||
'';
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@
|
|||
"vue-tsc": "^3.2.6"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vue-tsc && vite build",
|
||||
"build-rmo": "vite build vite/rmo",
|
||||
"build-sync": "vite build vite/sync",
|
||||
"dev-rmo": "vite serve vite/rmo",
|
||||
"dev-sync": "vite serve vite/sync",
|
||||
"generate-icons": "node generate-icons.js",
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ export default defineConfig({
|
|||
|
||||
build: {
|
||||
manifest: true,
|
||||
outDir: "static/gen",
|
||||
outDir: "static/gen/rmo",
|
||||
emptyOutDir: true,
|
||||
rollupOptions: {
|
||||
input: {
|
||||
main: path.resolve(__dirname, "../ts/main-rmo.ts"),
|
||||
main: path.resolve(__dirname, "./main.ts"),
|
||||
},
|
||||
output: {
|
||||
entryFileNames: "js/bundle.[hash].js",
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ export default defineConfig({
|
|||
|
||||
build: {
|
||||
manifest: true,
|
||||
outDir: "static/gen",
|
||||
outDir: "static/gen/sync",
|
||||
emptyOutDir: true,
|
||||
rollupOptions: {
|
||||
input: {
|
||||
main: path.resolve(__dirname, "index-sync.html"),
|
||||
main: path.resolve(__dirname, "./main.ts"),
|
||||
},
|
||||
output: {
|
||||
entryFileNames: "js/bundle.[hash].js",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue