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

WIP add vite support for central vite.config.js #1682

Merged
merged 5 commits into from
Nov 2, 2023

Conversation

dcblogdev
Copy link
Collaborator

WIP

This PR allows for the main vite.config.js to load paths from the base application as well as from modules. The idea is to have a single place to load all the css and js files into vite.

This is OPT in, the default setup that now exists allows you to load vite into a module. That will remain. This is to optionally load all assets globally.

The main vite.config.js will need to be updated to use a new vite-module-loader.js file. This needs to be published by running:

php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider" --tag="vite"

This created a file called vite-module-loader.js inside the project root.

Now vite.config.js will combine all paths from modules as well as those defined in this file.

import {defineConfig} from 'vite';
import laravel from 'laravel-vite-plugin';
import collectModuleAssetsPaths from './vite-module-loader.js';

const paths = [
    'resources/css/app.css'
];

const allPaths = await collectModuleAssetsPaths(paths, 'Modules');

export default defineConfig({
    plugins: [
        laravel({
            input:  allPaths,
            refresh: true,
        }),
    ],
});

Modules vite.config.js should be updated to contain only the assets:

export const paths = [
    'Modules/Books/resources/assets/sass/app.scss',
    'Modules/Books/resources/assets/js/app.js',
];

Then in the layout file to load all assets use:

@vite(\Nwidart\Modules\Module::getAssets())

@dcblogdev dcblogdev merged commit bcde104 into master Nov 2, 2023
8 checks passed
@dcblogdev dcblogdev deleted the feature/add-vite-support branch November 2, 2023 15:25
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 this pull request may close these issues.

1 participant