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

Option to inline CSS (global or modules) - build.inlineCss #4883

Closed
4 tasks done
kimsible opened this issue Sep 8, 2021 · 1 comment
Closed
4 tasks done

Option to inline CSS (global or modules) - build.inlineCss #4883

kimsible opened this issue Sep 8, 2021 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@kimsible
Copy link

kimsible commented Sep 8, 2021

Clear and concise description of the problem

Hi,

I'm using Vite for an app plugin. The plugin need to dist bundles of modules JS and CSS files to run in the app environment.
So I must use the build.lib option and build.watch with an outDir out of the project root for development.

I use the Rollup plugin livereload for js files, it's work pretty nice but unfortunately the CSS files are merged in a global css file outside of the plugin directory at the installation.

So the only way to develop CSS in live would be to inline them. I use CSS modules automatically bundled on build mode.

So CSS modules are well watched by Rollup but in this case it's useless since the CSS can't be reload by the main app.

Suggested solution

An option build.inlineCss: false | true (default to false) to inject it in the document.head with Javascript instead of creating the bundle.

Alternative

If there are any other solution for example with Rollup, I'm open to suggestions.

Or maybe I have a wrong approach of Vite.js, the initial problem was that the architecture of these plugins are considered as a library for Vite since there is no entry file index.html or main.js.

I found that issue #4454, it's not really the same problem but it raises the lack flexibility for assets (css included) on library mode.

Additional context

Here is the vite.config.js

https://github.com/kimsible/peertube-plugin-upload-limits/blob/master/vite.config.js

import { resolve } from 'path'
import { loadEnv } from 'vite'
import pkg from './package.json'
import livereload from 'rollup-plugin-livereload'
import copy from 'rollup-plugin-copy'

// npx vite build -m development - build and watch without minifying in PeerTube environment
// npx vite build -m staging - build without minifying
// npx vite build [-m production] - build and minify

export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd(), 'PEERTUBE_')
  const buildPeerTubeDistPath = () => env.PEERTUBE_PATH && resolve(env.PEERTUBE_PATH, `./storage/plugins/node_modules/${pkg.name}/`)

  return {
    build: {
      outDir: resolve(buildPeerTubeDistPath() || './', 'dist'),
      watch: mode === 'development',
      minify: mode === 'production' && 'terser',
      lib: {
        entry: 'client/common-client-plugin.js',
        name: pkg.name,
        formats: ['es'],
        fileName: () => 'common-client-plugin.js'
      },
      commonjsOptions: {
        include: ['./helpers/shared-helpers.js', './helpers/client-helpers.js'] // Keep commonjs for helpers
      },
      rollupOptions: {
        output: {
          chunkFileNames: 'assets/[name].js',
          assetFileNames: 'assets/[name][extname]'
        }
      }
    },
    plugins: [
      mode === 'development' && livereload(),
      copy({
        copyOnce: true,
        flatten: true,
        hook: 'writeBundle',
        targets: [
          { src: 'node_modules/mediainfo.js/dist/MediaInfoModule.wasm', dest: 'dist/assets/static' }
        ]
      })
    ]
  }
}

Validations

@sapphi-red
Copy link
Member

Closing as it is a duplicate of #1579.
But I think this could be solved by https://github.com/thgh/rollup-plugin-livereload#options.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2022
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed feat: css enhancement: pending triage feat: library mode labels May 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants