nystudio107 / craft-vite

Allows the use of the Vite.js next generation frontend tooling with Craft CMS
MIT License
51 stars 15 forks source link

Output path to javascript files via craft.vite.entry #28

Closed ryanfoote closed 2 years ago

ryanfoote commented 2 years ago

Question

I have a need to output the build versions of select CSS and Javascript files from a site. I have the CSS contents output with craft.vite.inline(craft.vite.entry("file.css")), but attempting to do the same for a corresponding Javascript file nets a return of just the development site base URL when craft.vite.entry("file.js") is called. The docs suggest that craft.vite.entry supports resolving a path to a built Javascript file, unless I'm misinterpreting.

Additional context

Snippet of my vite.config.js:

build: {
            emptyOutDir: false,
            manifest: true,
            outDir: './web/',
            rollupOptions: {
                input: {
                    about: '/_src/vite/about/index.ts',
                }
            },
        },

Example contents of one of the Typescript files that goes into the rollup config:

import '../scss/about.scss';

import '../js/about.js';

Thanks!

khalwat commented 2 years ago

I'm curious about the use-case here? Is there a reason you can't use craft.vite.script() which will include the JS as well as the CSS?

khalwat commented 2 years ago

Will re-open if more information is provided.