Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack.js regex problems (linux and windows) #8

Open
ofbeaton opened this issue Jul 12, 2015 · 4 comments
Open

webpack.js regex problems (linux and windows) #8

ofbeaton opened this issue Jul 12, 2015 · 4 comments

Comments

@ofbeaton
Copy link

The test line in webpack.js is incorrect for all systems and has 2 issues and 1 possible source of problems for users building on the tutorial.

 module: {
    loaders: [
      {
        test: /src\/.+.js$/,
        exclude: /node_modules/,
        loader: 'babel'
      }
    ]
  }

Please note the 2nd . is not escaped, it should read /src\/.+\.js$/. This was undetected because the regex still works even if it does not match properly.

However real problems begin on windows, the \/ slash doesn't work, producing a Unexpected reserved word You may need an appropriate loader to handle this file type. error.

This can be fixed by accepting either slash, with the regex /src(\/|\\).+\.js$/.

Finally, a specific user may expand and convert the client.js into a client.jsx and change their entry line, but find things stop working. Or they may use this as a learning project and copy it to another project where their entry is a jsx. You could help them out by giving them a reg ex that handles this case, in the form of: /src(\\|\/).+\.jsx?$/ which takes js or jsx.

I imagine this improvement can be made your flux tutorial as well.

@ofbeaton
Copy link
Author

In the react-hot-boilerplate I saw there might be an even better to this, by specifying the src directory in a include instruction instead of the regex and exclude.

module: {
    loaders: [{
      test: /\.jsx?$/,      
      loader: 'babel-loader',
      include: path.resolve(__dirname, '../src')
    }]
  }

This bring sthe test in line with what you will find in most examples, and you don't have to worry about having to start excluding things like bower components down the line.

@wwsun
Copy link

wwsun commented Oct 9, 2015

good issue

@waspar
Copy link

waspar commented Mar 31, 2020

5 years! 5 years have passed since ...
We were young in those years and believed!
Do not judge us strictly, everyone wants to believe!

@waspar
Copy link

waspar commented Mar 31, 2020

The real problem is not to define a delimiter.
It can simply be saved into a variable and changed depending on the system.

The real problem is to apply the capture group after RegEx is running, like this:

loader: 'url-loader',
options: {
	regExp: /src\\(.*)/i,
	name: '[1]',
	limit: 8192,
},

Windows will not use "/" (from [1]) in the path for new file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants