trunk icon indicating copy to clipboard operation
trunk copied to clipboard

Issue importing snippet for popperjs

Open ctron opened this issue 4 years ago • 1 comments

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

ctron avatar Dec 16 '21 17:12 ctron

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"
  }
}

ctron avatar Dec 17 '21 11:12 ctron

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.

github-actions[bot] avatar Oct 27 '23 00:10 github-actions[bot]

Yea, let's close this one. I am using https://github.com/ctron/popper-rs/ now.

ctron avatar Oct 27 '23 06:10 ctron