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

copy loader does not replace import statements #2924

Closed
gyfchong opened this issue Feb 15, 2023 · 2 comments
Closed

copy loader does not replace import statements #2924

gyfchong opened this issue Feb 15, 2023 · 2 comments

Comments

@gyfchong
Copy link

gyfchong commented Feb 15, 2023

Trying to use the copy loader to copy my scss files to the outDir however the result isn't what I expected.

esbuild.config.js

esbuild
  .build({
    entryPoints: ["./src/index.ts"],
    outdir: "./dist",
    bundle: true,
    loader: { ".module.scss": "copy" },
  })

Component

import React from "react"
import styles from "./ExampleComponent.module.scss"

export const ExampleComponent = (): JSX.Element => (
  <div className={styles.exampleComponent}>
    ExampleComponent FUTURE
  </div>
)

The output scss file is copied here: ./dist/ExampleComponent.module-5ETYEIC6.scss
The resulting compiled component ./dist/components/ExampleComponent.js

var ExampleComponent_module_scss_1 = __importDefault(require("./ExampleComponent.module.scss"));

Expected

At the very least, I understood that the resulting compiled component ./dist/components/ExampleComponent.js should have the import replaced:

var ExampleComponent_module_scss_1 = __importDefault(require("../ExampleComponent.module-5ETYEIC6.scss"));

And what I think would be better is the output scss file is copied to the same directory as the component itself:./dist/components/ExampleComponent.module-5ETYEIC6.scss

@evanw
Copy link
Owner

evanw commented Feb 15, 2023

I can't reproduce this. The import path does seem to be replaced when I do this. Please provide a self-contained way to reproduce the issue.

@gyfchong
Copy link
Author

gyfchong commented Feb 15, 2023

Ah apologies, I was using tsc to compile the typescript files and esbuild separately to copy the scss files and I think tsc overrides the files which esbuild outputs.

This works if esbuild is the only bundler

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