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

why not pass the transform sourcemap to webpack #154

Open
luhc228 opened this issue Aug 15, 2022 · 4 comments
Open

why not pass the transform sourcemap to webpack #154

luhc228 opened this issue Aug 15, 2022 · 4 comments

Comments

@luhc228
Copy link

luhc228 commented Aug 15, 2022

Hi~ I'm now using unplugin to write a plugin and the plugin will be transformed to webpack plugin and esbuild plugin.

I only use one plugin to transform the .jsx file. In other words, there is only one loader to handle .jsx file. So the transform function's param, map is undefined. But after I transform the .jsx file, I get the res.map value which is not the undefined. I am confused why the unplugin use the map first but not the res.map?

callback(null, res.code, map == null ? map : (res.map || map))

Here is how I use the unplugin transform hook:
https://github.com/ice-lab/ice-next/blob/f5755a0c0afdda87b97393ce6dc44f0ac9b4db84/packages/webpack-config/src/unPlugins/compilation.ts#L104

webpack loader load order: https://webpack.js.org/contribute/writing-a-loader/#complex-usage

@antfu
Copy link
Member

antfu commented Aug 15, 2022

If there was no map from the beginning and we provide a map, it will cause Webpack to throw an error on merging the sourcemap with null

@luhc228
Copy link
Author

luhc228 commented Aug 15, 2022

I make a change like these in node_modules/unplugin/dist/webpack/transform.js, it works. So will the unplugin makes a change? @antfu

- callback(null, res.code, map == null ? map : (res.map || map)) 
+ callback(null, res.code, res.map || map)

@antfu
Copy link
Member

antfu commented Aug 29, 2022

I would need a reproduction to confirm this is a valid fix.

@luhc228
Copy link
Author

luhc228 commented Aug 30, 2022

@antfu Thank you for your replying.

Here is my demo which can reproduct the problem.

You can install the dependencies and the run the script npm start to start the dev server.

Well, u can see this line. I console the transform result and the sourcemap is correct.

But the final sourcemap is incorrect.

image

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