vite icon indicating copy to clipboard operation
vite copied to clipboard

Get rid of CSS in JS output files & extract CSS into separate file.

Open otabekoff opened this issue 3 years ago • 1 comments

Description

Let's say I am preprocessing SCSS and extracting preprocessed styles into style.css. I am not able to get rid of CSS in my cjs.js | es.js | iife.js | umd.js output files. Globally imported SCSS is being preprocessed and being added into the design of every component. The output files become too large If I add a few more components because of this. How I can resolve this issue?

Suggested solution

I do'nt know the solution. I think, this is a bug. So I am asking help to solve to this. Because this is an issue.

Alternative

No response

Additional context

My vite configuration is:

// vite.config.js
const path = require('path');
const { defineConfig } = require('vite');
const vue = require('@vitejs/plugin-vue');

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "src/assets/styles/main.scss";`

      }
    }
  },
  build: {
    lib: {
      formats: ['es', 'umd', 'cjs', 'iife'],
      entry: path.resolve(__dirname, 'src/entry.js'),
      name: 'MyUI',
      fileName: (format) => `myui.${format}.js`,
    },
    rollupOptions: {
      external: ['vue'],
      output: {
        // Provide global variables to use in the UMD build
        // Add external deps here
        globals: {
          vue: 'Vue',
        },
      },
    },
  },
  resolve: {
    alias: {
      '@/': `${path.resolve(__dirname, 'src')}/`
    }
  },
  plugins: [vue()],
  server: {
    fs: {
      allow: [".."],
    },
  },
});

Validations

otabekoff avatar Jul 28 '22 18:07 otabekoff

Hello @otabekoff. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

github-actions[bot] avatar Jul 29 '22 02:07 github-actions[bot]