Giter Club home page Giter Club logo

Comments (4)

khalwat avatar khalwat commented on August 12, 2024

I think you probably should not be loading CSS inside of your config/general.php file but:

Vite::$plugin->viteService->entry($path)

https://github.com/nystudio107/craft-plugin-vite/blob/develop/src/variables/ViteVariableTrait.php#L83

from craft-vite.

webrgp avatar webrgp commented on August 12, 2024

Here is some context: I am using doublesecretagency/craft-cpcss plugin to load some custom styling in the control panel, which I generate using Vite. In it's settings I am referencing a custom alias @controlPanelCss.

In the general.php file I have this:

use craft\helpers\App;
use nystudio107\vite\Vite;

return [
    ...
    'aliases' => [
        ...
        '@controlPanelCss' => App::env('SITE_URL') . Vite::$plugin->vite->entry('src/js/website-styles.css'),
        ...
    ],
    ...
];

But now I get this error:

Fatal error: Uncaught Error: Typed static property nystudio107\vite\Vite::$plugin must not be accessed before initialization in /var/www/html/cms/config/general.php:15 Stack trace: #0 /var/www/html/cms/vendor/craftcms/cms/src/services/Config.php(277): include() #1 /var/www/html/cms/vendor/craftcms/cms/src/services/Config.php(269): craft\services\Config->_configFromFileInternal('/var/www/html/c...') #2 /var/www/html/cms/vendor/craftcms/cms/bootstrap/bootstrap.php(166): craft\services\Config->getConfigFromFile('general') #3 /var/www/html/cms/vendor/craftcms/cms/bootstrap/web.php(40): require('/var/www/html/c...') #4 /var/www/html/cms/web/index.php(11): require('/var/www/html/c...') #5 {main} thrown in /var/www/html/cms/config/general.php on line 15

Any thoughts?

from craft-vite.

khalwat avatar khalwat commented on August 12, 2024

Plugins are not loaded yet when general.php is executed.

I'd suggest just writing a little custom module to load your CSS, ala: https://github.com/nystudio107/craft/blob/craft-vite/cms/modules/sitemodule/src/SiteModule.php#L111

from craft-vite.

webrgp avatar webrgp commented on August 12, 2024

Thanks! I will pursue this path.

from craft-vite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.