Skip to content

Instantly share code, notes, and snippets.

@hrsetyono
Last active July 10, 2022 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrsetyono/4c26804b9ff7fc895878d60296fe884e to your computer and use it in GitHub Desktop.
Save hrsetyono/4c26804b9ff7fc895878d60296fe884e to your computer and use it in GitHub Desktop.
Vite for WordPress (work in progress, hot reload not yet working)
{
"name": "my-app",
"private": true,
"repository": {
"type": "git",
"url": "git+https://github.com/username/my-app"
},
"dependencies": {},
"devDependencies": {
"sass": "^1.53.0",
"vite": "^2.9.9",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2"
},
"scripts": {
"dev": "vite",
"build": "vite build"
}
}
import { defineConfig } from 'vite';
export default defineConfig({
base: '',
build: {
outDir: 'dist',
assetsDir: '',
rollupOptions: {
input: {
app: './assets/js/app.js',
},
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]',
},
},
},
server: {
open: 'http://mysite.test'
}
plugins: [],
});
@hrsetyono
Copy link
Author

hrsetyono commented Jul 10, 2022

This is a work in progress. Hot Reload, the most important feature, is still not working.

Idea: Replace assets URL with http://localhost:3000 and somehow add module to the script tag?

Solution that replace enqueue: https://github.com/idleberg/php-wordpress-vite-assets

Seems overkill, everything should work using the native wp_enqueue_style and wp_enqueue_script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment