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

Resolving links that start with "#" (e.g. url(#abc) ) #192

Open
MorisR opened this issue Nov 3, 2021 · 1 comment
Open

Resolving links that start with "#" (e.g. url(#abc) ) #192

MorisR opened this issue Nov 3, 2021 · 1 comment

Comments

@MorisR
Copy link

MorisR commented Nov 3, 2021

Hey,
It's my first time using rollup as a bundler and I'm facing a strange bug when it comes to handling css "url()" values

I'm importing a less file with the following css class in it

.test{
  fill: url("#abc");
}

Expected:
the code snippet to stay the same

Reality:
the following asset file is getting generated
the generated asset

and is being referenced in the output css file, like so

.test {
  fill: url("./index-bd52cf7f.js#abc");
}

This is the rollup config file for reference

import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import styles from 'rollup-plugin-styles';
import path from 'path';
import { RollupOptions } from 'rollup';
import pkg from './package.json';

const extensions = ['.ts', '.tsx', '.js', '.jsx', '.json'];

export default [
  {
    input: 'src/index.ts',
    output: [
      {
        dir: pkg.module,
        format: 'es',
        preserveModules: true,
        preserveModulesRoot: path.resolve(__dirname, 'src'),
        esModule: true,
        assetFileNames: '[name][extname]',
      },
    ],
    plugins: [
      peerDepsExternal({
        includeDependencies: true,
      }),
      resolve({
        extensions,
      }),
      commonjs(),
      styles({
        config: true,
        mode: ['extract', 'index.css'],
        less: {
          javascriptEnabled: true,
        },
        autoModules: true,
      }),
      typescript({
        // useTsconfigDeclarationDir: true,
      }),
    ],
  },
] as RollupOptions[];
@MorisR MorisR changed the title Resolving links that start with # (e.g. url(#abc)) Resolving links that start with "#" (e.g. url(#abc)) Nov 3, 2021
@MorisR MorisR changed the title Resolving links that start with "#" (e.g. url(#abc)) Resolving links that start with "#" e.g. url(#abc) Nov 3, 2021
@MorisR MorisR changed the title Resolving links that start with "#" e.g. url(#abc) Resolving links that start with "#" (e.g. url(#abc) ) Nov 3, 2021
@diego-antonelli
Copy link

I am also having the same issue when my css uses the ID of an SVG

.ant-empty-img-default-path-2 {
  fill: url(#linearGradient-1);
}

Error:

(styles plugin) Error: Unresolved URL `#linearGradient-1` in `fill: url(#linearGradient-1)`

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

2 participants