Created on 21 March 2023, almost 2 years ago
Updated 22 November 2023, about 1 year ago

Explore possible integration with Single Directory Components ✨ Add Single Directory Components as a new experimental module Fixed and their auto generated asset libraries.

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡΅πŸ‡±Poland wotnak

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @wotnak
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    Component assets are loaded under the sdc extension with a library id EXTENSION--COMPONENT.
    Asset paths are relative to the sdc module root. This code checks if it's processing a component in the currently active theme and changes the asset path to the bundle output.

    I'm using unocss, so component and template twig files need to get parsed to convert the tailwind classes.

    Here is a working config.

    // vite.config.js
    import UnoCSS from 'unocss/vite';
    import { defineConfig } from 'vite';
    import liveReload from 'vite-plugin-live-reload';
    import glob from 'glob';
    export default (({ mode }) => {
      return defineConfig({
        plugins: [
          UnoCSS(),
          liveReload(__dirname + '/**/*.(php|theme|twig|module)'),
        ],
        build: {
          assetsDir: '.',
          emptyOutDir: true,
          sourcemap: true,
          manifest: true,
          rollupOptions: {
            input: [
              './src/main.js',
              ...glob.sync('components/**/*.css')
            ],
            output: {
              entryFileNames: `[name].js`,
              assetFileNames: `[name].[ext]`,
            },
          },
          css: { devSourcemap: true },
          server: {
            host: true,
            port: 3000,
            origin: 'https://node.lndo.site',
          },
        },
      });
    });
    
    // .lando.yml
    name: uno-site
    recipe: drupal10
    config:
      webroot: web
    proxy:
      node:
        - node.mantra.lndo.site:3000
    services:
      node:
        type: node:18
        ssl: true
        sslExpose: false
        port: 3000
        scanner: false
    tooling:
      npm:
        service: node
        cmd: npm
      node:
        service: node
        cmd: node
      npx:
        service: node
        cmd: npx
    
    //uno.config.js
    import {
      defineConfig, presetTypography, presetUno, presetWebFonts,
    } from 'unocss';
    
    export default defineConfig({
      content: {
        pipeline: {
          include: [
            /\.(twig)($|\?)/,
          ],
        },
        filesystem: [
          'components/**/*.twig',
          'templates/**/*.twig'
        ],
      },
      presets: [
        presetUno(),
        presetTypography(),
        presetWebFonts(),
      ],
    });
    
    // theme.libraries.yml
    styles:
      vite: true
      js:
        src/main.js: {}
    

    The branch includes a fix from the related issue to automatically load bundled assets if needed.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I was getting errors in Gin when it's the active admin theme. Changing it to use the default theme for now but all the logic for checking components needs refinement. Might need an "enable components" setting.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I built a map component and needed some library dependencies. You can't add those as libraries directly to the component, so I put it in my theme and made that library a component dependency. I'd prefer to keep it all in the component to encapsulate the code better since I don't need those libraries anywhere else.

    I am thinking vite could bundle the component dependencies by making a js file that includes them and my own init script. The vite module would use the manifest file to load those dependencies, but would have to respect dependency order.

    There's some crossover with https://www.drupal.org/project/vite/issues/3392517 ✨ Support @vitejs/plugin-react Active but different use cases.

  • Status changed to Fixed about 1 year ago
  • πŸ‡΅πŸ‡±Poland wotnak

    Committed SDC integration in https://git.drupalcode.org/project/vite/-/commit/4fee955a75ceac335adfe82.... Instructions are in the README https://git.drupalcode.org/project/vite#sdc-integration.

    Basically for SDC is required the same configuration as for normal theme/module libraries, only in libraryOverrides in component definition instead of in .libraries.yml.

  • πŸ‡΅πŸ‡±Poland wotnak

    Available in the 1.1.1 β†’ release.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024