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

sourceMappingURL includes full file path which breaks sourcemaps #794

Open
trymeouteh opened this issue Aug 8, 2024 · 0 comments
Open

Comments

@trymeouteh
Copy link

trymeouteh commented Aug 8, 2024

When you use the --sourcemap argument in the CLI to generate the CSS builds with sourcemaps, the sourceMappingURL in the CSS file will include the full file path which breaks the sourcemaps. This will make it impossible to use sourcemaps with projects that structure their files in the following manner where src directory is where the source code is stored, dist directory is where the builds/bundles are stored and package.json is stored in the root directory.

  • src/
  • dist/
  • package.json

In the code below, the builds are stored in the dist directory, while the CSS source code is stored in the src directory.

This is my simple code to reproduce this...

- src/
   - stylesheet.css
- dist
   - my-package.css
   - my-package.css.map
- demo.html
- bundle.css
- package.json

bundle.css

@import 'src/stylesheet.css';

demo.html

<link rel="stylesheet" href="dist/my-package.css">

package.json

{
  "name": "my-package",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
   "build": "lightningcss --bundle bundle.css -o dist/my-package.css --sourcemap"
  },
  "devDependencies": {
    "lightningcss-cli": "^1.24.1"
  }
}

src/stylesheet.css

body {
	background-color: red;
}

dist/my-package.css output

body {
	background-color: red;
}
/*# sourceMappingURL=dist/my-package.css.map */

What I expected from the dist/my-package.css output. Instead of dist/my-package.css.map as a sourcemap file path, the sourcemap file path is my-package.css.map.

body {
	background-color: red;
}
/*# sourceMappingURL=my-package.css.map */

This is caused by the CLI command in package.json...

lightningcss --bundle bundle.css -o dist/my-package.css --sourcemap

The CLI command sets the output file path to dist/my-package.css. The dist/ file path is added to the sourcemap file path in the dist/my-package.css file...

/*# sourceMappingURL=dist/my-package.css.map */

The dist/ file path breaks the sourcemap since the my-package.css.map file is always in the same directory as the my-package.css file and therefore the source map file path should always be

/*# sourceMappingURL=my-package.css.map */
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