Skip to content

module.rules.include forward slash in windows 10 #5327

Closed

Description

@raulsebastianmihaila

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

What is the current behavior?
Webpack doesn't use the module.rules.include option properly on windows 10.

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

module.exports = {
  // ... removed for brevity
  module: {
    rules: [
      {
        test: /\.js$/,
        include: `${__dirname}/src`,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['react'],
              plugins: ['transform-es2015-modules-commonjs']
            }            
          }
        ]
      }
    ]
  },
  // ... removed for brevity
};

Because I'm using a forward slash in include: `${__dirname}/src` , the path is actually not included when babel does its work. If I replace it with include: `${__dirname}\\src` , it works. However the entry option works just fine, which is entry: `${__dirname}/src/js/main.js` .

What is the expected behavior?
Webpack should treat forward slashes the same in the entry and module.rules.include options, meaning that forward slashes should work on windows the same as \\.
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.
windows 10, webpack 3.3.0, node 6.9.1, npm 3.10.10

Activity

  1. sokra commented on Jul 20, 2017

    @sokra
    Member

    include matches the absolute path of the resolved file (see also https://webpack.js.org/configuration/module/#condition). Best use path.resolve(__dirname, "src") as value to include.

    webpack automatically fixes your incorrect slashes for the entry option.

  2. raulsebastianmihaila commented on Jul 20, 2017

    @raulsebastianmihaila
    Author

    It would be nice if webpack could fix my incorrect slashes everywhere (since the solution for that is already there) as this would make it easy to use the same config on windows and linux.

  3. rally25rs commented on Mar 14, 2019

    @rally25rs

    This unfortunately is the same with the module.rules.test which makes it difficult to use the most common use case; using a regex. You have to [\/\\] each directory 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions