question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specify output directory with dynamic import

See original GitHub issue

Do you want to request a feature or report a bug?

Neither

What is the current behavior?

I am wondering if it is possible to specify an output directory per dynamic import context:

import(/* webpackChunkName: "svg-" */ `resources/assets/images/svg/${this.name}.svg`)
    .then((module) => {
        this.svg = module;
    }
).catch(error => 'An error occured while loading the svg');

When using something like the above I would like to specify the output directory of these files so they end up in: public/js/svg/.

I am currently doing it by using this:

output: {
    publicPath: '/',
    chunkFilename: 'js/svg/[name].js'
},

This is obviously not flexible since it will do this for all dynamic imports so I can’t re-use it for anything but SVG’s.

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
victorwpbastoscommented, Sep 26, 2017

In my case, [request] is always interpreted literally as somefilename.[request].js. Anyone with the same problem?

2reactions
dobromir-hristovcommented, Jul 31, 2017

Well technically you could do /* webpackChunkName: "/js/svg/svg-[name]" * but that could lead to other problems i think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify filename pattern in dynamic import with ...
If we do import(`intl/locale-data/jsonp/${language}.js`);. Then all files in intl/locale-data/jsonp/*.js are compiled to output.
Read more >
Dynamic imports - The Modern JavaScript Tutorial
Export and import statements that we covered in previous chapters are called “static”. The syntax is very simple and strict.
Read more >
How to Dynamically Import ECMAScript Modules
You can import modules dynamically if you use import as a function — import(pathToModule) — a feature available starting ES2020.
Read more >
Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code into manageable chunks. ... Setting a custom build directory.
Read more >
How code-splitting and dynamic Import works - WPACK.IO
Relying on this theory, we have set output.publicPath to be /dist/ . So if './src/main.js' has some sort of import(' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found