Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Webpack: How do I use magic comments to import a file into a file that will be published as a library then imported into a different application

I have a file published as umd library with a dynamic import that builds a select list of widgets based on configuration options. This is all working great in that the main js and widget js files are being published when I run the library directly. When I import the library into another project. It attempts to the path the widget import based upon the root of the url of the project instead of based off the url of the umd. Is there a way I can force the dynamic import to base its pathing off the absolute path of the library? I couldn't find anything in magic comments that would help.

My secondary option would be to just publish each of the widgets as their own distinct libraries and then webpackIgnore the import which I think should work

webpack config output:

output: {
      publicPath: "",
      path: require("path").resolve("publish/__dist"),
      filename: "[name].js",
      library: {
        name: "widget-container",
        type: "umd",
        umdNamedDefine: true,
      },
    },

import in library:

import(/* webpackChunkName: "widgets/widget" */ `../widgets/${b.slug}/js/widget.js`)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!