Closed khalidabuhakmeh closed 1 year ago
A follow-up on my further investigation. Turns out that Vite post-processing is done on the _site
directory. That means, by Vite convention, it will only process/copy JavaScript files under _site/public
.
This creates a weird difference between development and production-build modes. I'm still investigating, but any ideas are welcome.
This issue is related to this one. https://github.com/11ty/eleventy-plugin-vite/issues/28
Hi @khalidabuhakmeh ,
I've prepared a minimal eleventy+eleventy-plugin-vite+video.js demo[1], basically I'm reference the node modules like this (shortened for the sake of exemplification, Disclaimer: I'm not an expert in this asset bundling business):
// packages.json
{
"devDependencies": {
"@11ty/eleventy": "^2.0.0",
"@11ty/eleventy-plugin-vite": "^4.0.0",
"sass": "^1.58.0",
"video.js": "^8.0.4"
}
}
# layout.njk
<html>
{{ content | safe }}
<script src="{{ '/assets/app.js' }}" type="module"></script>
</html>
# app.js
import videojs from 'video.js';
# app.scss
@import 'video.js/dist/video-js.min.css';
[1] https://github.com/tombreit/eleventy-vite-minimal/tree/vite-videojs
👋 Hello,
I'm trying to get Vite to process JavaScript files resolved from
node_modules
on the build step, but it skips them entirely, leaving my site broken.Here is my Vite configuration with the
resolve
keyword.And here is my script tag from the file template.
The file is served correctly during development, but when I call
build
(node --require esbuild-register node_modules/.bin/eleventy
), thesrc
of my script tag is unchanged. Although, Vite recognizes the path to the css file and processes that correctly.Vite suggest to add a
type="module"
to the script, but it breaks the dependency.I'm unsure if this is a bug in the plugin, Vite, or a combination of the two. If anything, this might be a "heads up" kind of issue.