kucrut / vite-for-wp

Vite integration for WordPress plugins and themes development.
GNU General Public License v2.0
260 stars 29 forks source link

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

Closed airman5573 closed 5 months ago

airman5573 commented 12 months ago

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 commented 11 months ago

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',
        },
    }),
}