Comments (6)
BOOM! You sir, have made my day!
Thanks so much for your help!
from craft-vite.
As I'm running it via Homestead, do I need to use the devServerInternal and checkDevServer options? I'm not really sure what to put in there or what I'd need to configure on the Homestead VM.
No, you don't.
'devServerPublic' => 'http://localhost:3000/',
This probably should be whatever your Homestead VM is IP, it's listed in your Homestead.yaml
file. Mine is 192.168.10.10
so my settings would be:
'devServerPublic' => 'http://192.168.10.10:3000/',
...or if you set up hostnames, you can use them too.
Also you'll want to make one small change to the vite.config.js
to be compatible with the latest Vite 2.3.0 on Homestead, which is to add this:
server: {
host: '0.0.0.0',
},
So it'd look like this:
import legacy from '@vitejs/plugin-legacy'
import ViteRestart from 'vite-plugin-restart';
// https://vitejs.dev/config/
export default ({ command }) => ({
base: command === 'serve' ? '' : '/dist/',
build: {
manifest: true,
outDir: './web/dist/',
rollupOptions: {
input: {
app: '/src/js/app.ts',
}
},
},
plugins: [
legacy({
targets: ['defaults', 'not IE 11']
}),
ViteRestart({
reload: [
'./templates/**/*',
],
}),
],
server: {
host: '0.0.0.0',
},
});
The article has been updated with this information: https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms
Also make sure you are running all of your vite commands inside of your Homestead VM.
from craft-vite.
Thanks a lot - that's great and makes sense re the devServerPublic
. π
If I run the npm run dev
command inside Homestead, it runs, and going to my local domain in the browser loads the page with the styles etc. However, changing and saving the js
, css
, or twig
file from my code editor does nothing.
If I SSH into Homestead and change the files in the terminal using nano
it reloads as expected. Is this likely to be something wrong with my setup or with my config?
Here is my folder structure (I'm running all commands from the root (my-site) dir.
my-site/
βββ craft/
β βββ config/
β β βββ vite.php
β βββ templates/
β | βββ index.twig
| βββ web/
βββ src/
β βββ js/
β βββ app.js
βββ vite.config.js
Appreciate any pointers but if this is nothing to do with the plugin, feel free to send me on my way π
from craft-vite.
Oh - for Homestead, you have to turn polling on (it's the same with webpack or anything that uses chokidar to watch files).
Something like this:
import legacy from '@vitejs/plugin-legacy'
import ViteRestart from 'vite-plugin-restart';
// https://vitejs.dev/config/
export default ({ command }) => ({
base: command === 'serve' ? '' : '/dist/',
build: {
manifest: true,
outDir: './web/dist/',
rollupOptions: {
input: {
app: '/src/js/app.ts',
}
},
},
plugins: [
legacy({
targets: ['defaults', 'not IE 11']
}),
ViteRestart({
reload: [
'./templates/**/*',
],
}),
],
server: {
host: '0.0.0.0',
watch: {
usePolling: true,
},
},
});
refs: https://vitejs.dev/config/#server-watch & https://github.com/paulmillr/chokidar#api
from craft-vite.
I'm having a similar issue w/Homestead. Can't get the npm run dev
to load the site https://localhost:3000/
inside the homestead box. I get the following error:
This site canβt be reached. localhost refused to connect.
Running npm run build
to generate the build files, changing 'useDevServer' => false' and accessing the Craft project via hostname (
https://domain.test') shows the craft vite plugin working properly.
Under the server
block in vite.config.js
I have the following:
server: {
host: '0.0.0.0',
https: true,
watch: {
usePolling: true,
},
}
and config/vite.php
is set to
<?php
use craft\helpers\App;
return [
'useDevServer' => App::env('ENVIRONMENT') === 'dev',
'manifestPath' => '@webroot/dist/manifest.json',
'devServerPublic' => App::env('DEFAULT_SITE_URL'),
'serverPublic' => App::env('DEFAULT_SITE_URL') . '/dist/',
'errorEntry' => 'src/js/app.js',
'cacheKeySuffix' => '',
'devServerInternal' => '',
'checkDevServer' => false,
'includeReactRefreshShim' => false,
'includeModulePreloadShim' => true,
'criticalPath' => '@webroot/dist/criticalcss',
'criticalSuffix' =>'_critical.min.css',
];
Switching devServerPublic
to https://localhost:3000/
makes no difference
from craft-vite.
@siebird port 3000 is the port that the devServer
runs off of. You load your website from the normal URL you always do.
The idea is that combined with the Vite plugin, your website will load your JS/CSS, etc. from the devServer
See this comment: #3 (comment)
from craft-vite.
Related Issues (20)
- CORS error (sitename.ddev.site <-> localhost:3000) HOT 1
- 400 Bad Request after starting vite dev HOT 1
- Template named "register" breaks HMR HOT 2
- criticalUrl in .env HOT 3
- Port 3000 now in use by DDEV HOT 1
- Access blocked by CORS: domain.site <> domain.site:3000 HOT 1
- `inline()` function not working with relative local path HOT 2
- craft.vite.asset no longer matches manifest format in Vite 3.x || 4.x HOT 3
- Generic "getHash" helper HOT 1
- Ability to prevent CSS from being extracted from the manifest HOT 1
- Multisite Compatible? HOT 2
- Twigpack::$plugin->manifest->getFileFromManifest() equivalent HOT 4
- Add registerAsset() function so register functionality can work directly with css HOT 1
- Your view on CSS style names coming from Craft's field HOT 2
- Multi-domain setup HOT 2
- .getCssInlineTags() function produces encoded output HOT 1
- Loading svg icons in css async (production) HOT 1
- Getting CORS and mim-type not allowed error with ddev HOT 5
- Add support for referencing src paths to craft.vite.inline() HOT 4
- Failed to connect to localhost port 3000 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from craft-vite.