thgh / rollup-plugin-scss

Rollup and compile multiple .scss, .sass and .css imports
MIT License
134 stars 47 forks source link

Output css file not included in root html #103

Open L3XAWeasel opened 1 year ago

L3XAWeasel commented 1 year ago

I'm using v4 and configured the plugin to run fine for me, with some limitations. One limitation is that the file created through the plugin is not loaded via my root html file (index.html). The stylesheet tag is just not added to the <head> object.

I need to add it by hand which i would like to circumvent because that also means i have to specify a fileName via the option to avoid the additional hash in the file name.

Below is my vite.config.ts

  export default defineConfig(({ command, mode }) => {
    const outDir = path.resolve(__dirname, '../../../target/classes/static/');
    return {
      resolve: {
        alias: [
          {
            find: '@',
            replacement: path.resolve(__dirname, 'src'),
          },
        ],
        extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.html', '.cjs', 'css', 'scss'],
      },
      plugins: [
        tsconfigPaths(),
        scss({
          processor: () => postcss([autoprefixer({ overrideBrowserslist: ['cover 90%', 'not dead'] }), cssnanoPlugin()]),
          fileName: 'index.css',
        }),
        splitVendorChunkPlugin(),
        viteCommonjs(),
        react(),
        legacy(),
        createHtmlPlugin({
          minify: true,
          entry: './src/index.tsx',
          template: './index.html',
        }),
      ],
      base: '/',
      mode: mode || 'production',
      css: {
        preprocessorOptions: {
          scss: {
            additionalData: `@import "./src/assets/scss/_variables.scss";`,
          },
        },
        devSourcemap: false,
      },
      build: {
        modulePreload: { polyfill: true },
        rollupOptions: {
          output: {
            format: 'module',
          },
        },
        outDir,
        emptyOutDir: true,
      },
      define: {
        __VERSION: version,
      },
    };