diff --git a/index.php b/index.php
index 36d2864..798b832 100644
--- a/index.php
+++ b/index.php
@@ -2,41 +2,27 @@
get_header();
?>
-
-
+
+
-
+
-
-
-
Hello!
-
Finally, it works!
-
Try to type something below and save it in editor without refresh the browser!
+
-
-
-
You can set background image too!
-
-
-
-
-
-
-
-
-
-
+
+
=3.0.0 <4.0.0",
@@ -1305,9 +1305,9 @@
}
},
"node_modules/vite": {
- "version": "5.0.10",
- "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.10.tgz",
- "integrity": "sha512-2P8J7WWgmc355HUMlFrwofacvr98DAjoE52BfdbwQtyLH06XKwaL/FMnmKM2crF0iX4MpmMKoDlNCB1ok7zHCw==",
+ "version": "5.0.11",
+ "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.11.tgz",
+ "integrity": "sha512-XBMnDjZcNAw/G1gEiskiM1v6yzM4GE5aMGvhWTlHAYYhxb7S3/V1s3m2LDHa8Vh6yIWYYB0iJwsEaS523c4oYA==",
"dev": true,
"dependencies": {
"esbuild": "^0.19.3",
diff --git a/package.json b/package.json
index 3813a3d..ae814c7 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
- "name": "wordpress-vite-theme",
+ "name": "vite-wordpress-theme",
"private": true,
- "version": "0.0.0",
+ "version": "1.0.0",
"type": "module",
"scripts": {
"dev": "rimraf ./assets/dist && vite",
@@ -10,8 +10,8 @@
},
"devDependencies": {
"rimraf": "5.0.5",
- "sass": "1.69.5",
- "vite": "5.0.10"
+ "sass": "1.69.7",
+ "vite": "5.0.11"
},
"dependencies": {
"bootstrap": "5.3.2"
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..8a4f405
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,39 @@
+# WordPress Vite.js starter theme
+
+![](screenshot.png)
+
+## Under the hood
+
+- [ES6](https://github.com/lukehoban/es6features#readme) for JavaScript
+- [SASS](http://sass-lang.com/) preprocessor for CSS following [SASS Guidelines](https://sass-guidelin.es/#the-7-1-pattern)
+- [Bootstrap 5](https://getbootstrap.com/docs/5.2/getting-started/introduction/) as CSS framework ([customizable with SASS](https://getbootstrap.com/docs/5.2/customize/sass/))
+- [Vite.js](https://vitejs.dev/) to compile theme assets and provide live reload
+
+## Requirements
+
+* [Node](https://nodejs.org/)
+
+## Usage
+
+First, clone this repository in your WordPress themes directory.
+
+Then, run the following commands in the theme's directory :
+
+ npm install
+
+Launch your watch for assets with :
+
+ npm run dev
+
+For production sites, create your build with :
+
+ npm run build
+
+## Vite & WordPress
+- All the static assets used in scss or js files (images, fonts, etc.) are copied as-is to the `dist` folder. The other images used directly in php files are
not copied.
+- To detect dev mode in php there is no `dist` folder
+
+## Troubleshooting [dev mode]
+
+- Vite needs to know the root path of your project so
you cannot use a subdirectory as the root of your WordPress installation.
+- If you haven't started the dev server, your assets will not be compiled just `npm run dev` and refresh page.
diff --git a/screenshot.png b/screenshot.png
index 5f112d0..dc4222c 100644
Binary files a/screenshot.png and b/screenshot.png differ
diff --git a/static/img/mono-log-unsplash.jpg b/static/img/mono-log-unsplash.jpg
deleted file mode 100644
index e9ef86c..0000000
Binary files a/static/img/mono-log-unsplash.jpg and /dev/null differ
diff --git a/static/img/tom-delanoue-unsplash.jpg b/static/img/tom-delanoue-unsplash.jpg
deleted file mode 100644
index 06d30ea..0000000
Binary files a/static/img/tom-delanoue-unsplash.jpg and /dev/null differ
diff --git a/static/svg/.gitkeep b/static/svg/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/style.css b/style.css
index 203fe53..58fa32c 100644
--- a/style.css
+++ b/style.css
@@ -1,9 +1,9 @@
/*
-Theme Name: Vite WordPress Starter theme
-Theme URI: http://www.wp-default.com/
+Theme Name: Vite WordPress starter theme
+Theme URI: https://github.com/oguilleux/vite-wordpress-starter-theme
Author: Olivier Guilleux
Author URI: https://www.olivier-guilleux.com
-Description: Theme for www.wp-default.com
+Description: Theme for an awesome team !
Version: 1.0.0
Text Domain: textdomaintomodify
*/
diff --git a/vite.config.js b/vite.config.js
index 0c969e1..4754011 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -10,7 +10,14 @@ import { defineConfig } from "vite";
import { resolve } from 'path';
import { glob } from 'glob';
+// Get the relative path of the vite.config.js file for the alias
+const fullPath = import.meta.url.slice(0, import.meta.url.lastIndexOf('/'));
+const getWpContentIndex = fullPath.indexOf('wp-content');
+const wpContentPath = fullPath.slice(getWpContentIndex);
+
export default defineConfig({
+ base: './',
+
plugins: [
{
handleHotUpdate({ file, server }) {
@@ -23,11 +30,6 @@ export default defineConfig({
css: {
devSourcemap: true,
- // preprocessorOptions: {
- // scss: {
- // additionalData: '@import "./src/scss/sass_imports.scss";',
- // }
- // }
},
build: {
@@ -36,6 +38,9 @@ export default defineConfig({
outDir: resolve(__dirname, 'assets/dist/'),
+ // don't base64 images
+ assetsInlineLimit: 0,
+
rollupOptions: {
input: {
'js/main': resolve(__dirname + '/assets/src/js/main.js'),
@@ -53,14 +58,19 @@ export default defineConfig({
chunkFileNames: '[name]-[hash].js',
assetFileNames: (assetInfo) => {
let extType = assetInfo.name.split('.');
- let extSuffix = extType[extType.length - 1];
- let name = assetInfo.name.split('/').pop();
- // stip extension
- name = name.replace(/\.[^/.]+$/, "");
- console.log(extSuffix);
- return `${extSuffix}/${name}-[hash][extname]`;
- },
+ // group fonts in a folder
+ if (extType[1] === 'woff' || extType[1] === 'woff2' || extType[1] === 'ttf') {
+ return 'fonts/[name]-[hash].[ext]';
+ }
+
+ // group images in a folder
+ if (extType[1] === 'gif' || extType[1] === 'jpg' || extType[1] === 'jpeg' || extType[1] === 'png') {
+ return 'img/[name]-[hash].[ext]';
+ }
+
+ return'[ext]/[name]-[hash].[ext]';
+ }
},
},
},
@@ -72,14 +82,13 @@ export default defineConfig({
},
// We need a strict port to match on PHP side.
- // You can change it. But, please update it on your .env file to match the same port
strictPort: true,
- port: 5173
+ port: 5173,
},
resolve: {
alias: {
- "@": resolve(__dirname, '../static/'),
+ '@': process.env.NODE_ENV === 'development' ? resolve(wpContentPath + '/static') : '/static'
}
},
});