Open
Description
Version
System:
OS: macOS 15.3.2
CPU: (12) arm64 Apple M2 Pro
Memory: 181.52 MB / 32.00 GB
Shell: 4.0 - /opt/homebrew/bin/fish
Browsers:
Chrome: 136.0.7103.114
Safari: 18.3.1
npmPackages:
@rslib/core: ^0.7.1 => 0.7.1
Details
I’m testing out rslib in a library I maintain. In the library, I use __webpack_nonce__
to provide a nonce for dynamically-inserted style tags.
The following code
declare const __webpack_nonce__: string | undefined;
const styleElement = document.createElement('style');
if (typeof __webpack_nonce__ !== 'undefined') {
styleElement.nonce = __webpack_nonce__;
}
styleElement.appendChild(document.createTextNode('/* jsxstyle */'));
document.head.appendChild(styleElement);
is transformed to this:
var __webpack_require__ = {};
(()=>{
__webpack_require__.nc = void 0;
})();
const styleElement = document.createElement('style');
styleElement.nonce = __webpack_require__.nc;
styleElement.appendChild(document.createTextNode('/* jsxstyle */'));
document.head.appendChild(styleElement);
but I would expect to see this instead:
const styleElement = document.createElement('style');
if (typeof __webpack_nonce__ !== 'undefined') {
styleElement.nonce = __webpack_nonce__;
}
styleElement.appendChild(document.createTextNode('/* jsxstyle */'));
document.head.appendChild(styleElement);
so that I can set __webpack_nonce__
in code that uses this library.
Reproduce link
https://github.com/jsxstyle/jsxstyle/tree/rslib
Reproduce Steps
- Add
__webpack_nonce__
to a library - Bundle the library with rslib