Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite5, manifest file is made at /dist/.vite #74

Closed
airman5573 opened this issue Dec 5, 2023 · 1 comment · Fixed by #92
Closed

vite5, manifest file is made at /dist/.vite #74

airman5573 opened this issue Dec 5, 2023 · 1 comment · Fixed by #92

Comments

@airman5573
Copy link

At vite5 manifest file is located at /dist/.vite directory.

So this code does not work.

add_action( 'wp_enqueue_scripts', function (): void {
	Vite\enqueue_asset(
		__DIR__ . '/dist',
		'assets/main.js',
		[
			'handle' => 'my-script-handle',
			'dependencies' => ['jquery'], // Optional script dependencies. Defaults to empty array.
			'css-dependencies' => [], // Optional style dependencies. Defaults to empty array.
			'css-media' => 'all', // Optional.
			'css-only' => false, // Optional. Set to true to only load style assets in production mode.
			'in-footer' => true, // Optional. Defaults to false.
		]
	);
} );

And I think

/**
 * Load production asset
 *
 * @since 0.1.0
 *
 * @param object $manifest Asset manifest.
 * @param string $entry    Entrypoint to enqueue.
 * @param array  $options  Enqueue options.
 *
 * @return array|null Array containing registered scripts & styles or NULL if there was an error.
 */
function load_production_asset( object $manifest, string $entry, array $options ): ?array {
	$url = prepare_asset_url( $manifest->dir );

So I think that asset_url and manifest->dir should be distinct.

By the way, I really like your project. Thanks.

@irshadahmad21
Copy link
Contributor

irshadahmad21 commented Dec 13, 2023

You can append this to plugins array in vite.config.ts to use the old style path.

{
	name: 'override-config',
	config: () => ({
		build: {
			// ensure that manifest.json is not in ".vite/" folder
			manifest: 'manifest.json',
		},
	}),
}

@kucrut kucrut mentioned this issue Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants