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.

inline loader not migrateable to webpack 5 when used in require.context

See original GitHub issue

Bug report

What is the current behavior?

The documentation in https://webpack.js.org/guides/asset-modules/#replacing-inline-loader-syntax to replace inline loaders with Asset Modules does not apply to require.context. Specifically, it doesn’t seem like I can exclude a source asset from being parsed by other loaders. This was possibly in webpack 4 with require.context("!raw-loader!./code", false, /\.js$/); but there seems to be no API for this behavior in webpack 5 i.e.

{
  test: /\.m?js$/,
  resourceQuery: /^(?!\?raw$).*/,
},
{
  resourceQuery: /raw/,
  type: "asset/source",
},
{
  test: /\.(js|jsx)$/,
  exclude: /node_modules/,
  use: ["babel-loader"],
},

does result in transpiled source assets.

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

  1. Clone https://github.com/eps1lon/webpack-asset-modules-source-require-context
  2. yarn install
  3. `yarn start´
  4. Open page

The source code is printed transpiled (notice the /*#__PURE__*/React.createElement transpilation artifact).

What is the expected behavior?

The source asset is not transpiled (or parsed by any other loader for that matter).

Other relevant information: webpack version: 5.21.1 Node.js version: 12.20.0 Operating System: Ubuntu 20.04.2 LTS Additional tools:

The issue seems similar to https://github.com/webpack/webpack/issues/5730?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:26 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Mar 15, 2021

@eps1lon sorry, typo, I mean prioritize

Could you summarize how I would write the initial set of rules without changing the rule that applies the babel-loader?

Right now only using resourceQuery: /^(?!\?raw$).*/,, we need think more about it

1reaction
alexander-akaitcommented, Mar 15, 2021

Intersect rules, please use:

module: {
    rules: [
      {
        type: "asset/source",
        resourceQuery: /raw/,
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        resourceQuery: /^(?!\?raw$).*/,
        use: ["babel-loader"],
      },
    ],
  },

otherwise test is preferred

Read more comments on GitHub >

github_iconTop Results From Across the Web

To v5 from v4 - webpack
This guide aims to help you migrating to webpack 5 when using webpack directly. ... to the latest webpack 4 version should not...
Read more >
Webpack dynamic require with loaders in require statement
Loaders are run only once at compile-time, which means after your require.context is compiled, it's just pure Javascript.
Read more >
Migrating to Webpack 5 at smallcase - Medium
We use webpack not only for our bundling process but for much more. We use a rather distinctive webpack setup. We use Post...
Read more >
marko - UNPKG
15, ### 4.18.5. 16. 17, - Fix issue with invoke tag migration when a inline control flow is used [#1366](https://github.com/marko-js/marko/pull/1366).
Read more >
Untitled
hosted_engine_setup - Do not try to sync at end of full_execution. ... Use vars instead of inline variables for include_tasks - Rename all...
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