Skip to content

Commit

Permalink
created watcher plugin to watch and update public dir
Browse files Browse the repository at this point in the history
  • Loading branch information
james0r committed Nov 6, 2023
1 parent a0401ff commit f296313
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
"@vitejs/plugin-basic-ssl": "^1.0.1",
"alpinejs": "^3.13.2",
"autoprefixer": "^10.4.16",
"chokidar": "^3.5.3",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"fs-extra": "^11.1.1",
"liquid-ajax-cart": "^2.0.2",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.27",
Expand Down
27 changes: 24 additions & 3 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import { resolve } from 'node:path'
import shopify from 'vite-plugin-shopify'
import pageReload from 'vite-plugin-page-reload'
import basicSsl from '@vitejs/plugin-basic-ssl'
import fs from 'fs'
import { watch } from 'chokidar';
import fs from 'fs-extra'

export default {
const watchStaticAssets = () => ({
name: 'watch-static-assets',
configureServer(server) {
const watcher = watch('./public/*', {
persistent: true
});

const copyAsset = async path => {
await fs.copy(path, `assets/${path.replace('public/', '')}`);
}

const removeAsset = async path => {
await fs.remove(`assets/${path.replace('public/', '')}`);
}

watcher.on('add', copyAsset);
watcher.on('change', copyAsset);
watcher.on('unlink', removeAsset);
}
})

export default {
clearScreen: false,
server: {
host: '127.0.0.1',
Expand All @@ -15,6 +35,7 @@ export default {
publicDir: true,
plugins: [
basicSsl(),
watchStaticAssets(),
shopify({
snippetFile: 'vite.liquid'
}),
Expand Down

0 comments on commit f296313

Please sign in to comment.