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

Output css file not included in root html #103

Open
L3XAWeasel opened this issue Dec 13, 2022 · 0 comments
Open

Output css file not included in root html #103

L3XAWeasel opened this issue Dec 13, 2022 · 0 comments

Comments

@L3XAWeasel
Copy link

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,
      },
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant