trunk
trunk copied to clipboard
Issue importing snippet for popperjs
I am importing popperjs using:
#[wasm_bindgen(module = "/src/js/popperjs.js")]
extern "C" {
#[wasm_bindgen(js_name = "createPopper")] pub fn create_popper(
reference: web_sys::Node,
popper: web_sys::Node,
opts: &JsValue,
) -> Instance;
}
This works fine with webpack, but with trunk it fails.
I generates the following import statement:
import { Popper } from './snippets/patternfly-yew-d917bb4852761436/src/js/popperjs.js';
And copies the snippet into the correct folder. However, the browser then fails with:
Uncaught SyntaxError: import not found: createPopper
It looks like I was able to fix this, by re-packing popper using rollup.
main.js:
export * from '@popperjs/core';
rollup.config.js:
import { nodeResolve } from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
export default {
input: 'main.js',
output: {
file: 'popperjs.js',
format: 'esm',
name: "popperjs",
globals: {
"@popperjs/core": "Popper",
}
},
plugins: [
nodeResolve(),
replace({
"preventAssignment": true,
"values": {
"process.env.NODE_ENV": JSON.stringify('production')
}
})
]
}
package.json:
{
"name": "popperjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "./node_modules/.bin/rollup -c"
},
"author": "",
"license": "MIT",
"dependencies": {
"@popperjs/core": "^2.11.0"
},
"devDependencies": {
"rollup": "^2.61.1",
"@rollup/plugin-node-resolve": "^13.1.1",
"@rollup/plugin-replace": "^3.0.0"
}
}
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Yea, let's close this one. I am using https://github.com/ctron/popper-rs/ now.