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

Fail to import asset by url when current script src has query params #2603

Closed
edoardocavazza opened this issue Dec 20, 2018 · 2 comments · Fixed by #2937
Closed

Fail to import asset by url when current script src has query params #2603

edoardocavazza opened this issue Dec 20, 2018 · 2 comments · Fixed by #2937

Comments

@edoardocavazza
Copy link
Contributor

  • Rollup Version: 0.66.6
  • Operating System (or Browser): MacOS 10.14.1
  • Node Version: 11.4.0

How Do We Reproduce?

// index.js
import IMAGE_URL from './image.png';

console.log(IMAGE_URL);
// rollup.config.js
export default {
    input: './index.js',
    output: {
        file: './bundle.js',
        format: 'umd',
    },
    plugins: [{
        load(id) {
            if (!id.endsWith('.png')) {
                return null;
            }
            let buffer = require('fs').readFileSync(id);
            let asset = this.emitAsset(path.basename(id), buffer);
            return `export default import.meta.ROLLUP_ASSET_URL_${asset};`;
        }
    }],
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script src="bundle.js?test=1"></script>
</body>
</html>

Expected Behavior

The IMAGE_URL value is http://localhost/image.png

Actual Behavior

The IMAGE_URL value is http://localhost/bundle.js?test=1/../image.png

@lukastaegert
Copy link
Member

I think this should be fixable by using the URL constructor a little more intelligently but I need to check.

@lukastaegert
Copy link
Member

Fix at #2937

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants