babel-loader complains about syntax errors in code that should be removed
jmanj78 opened this issue · comments
I have a .js
file with an entry that looks like this:
{
text: 'link text',
/// #if CONDITION
url: 'url/if/true'
/// #else
url: 'url/if/false
/// #endif
}
I have tried setting up my webpack.config.js rules in a couple of different ways, neither of which is currently working:
webpackConfig.rules version 1
[
{ test: /\.(js|jsx)$/,
use: [ 'babel-loader' ],
exclude: /node_modules/ },
...
{ test: /\.(js|jsx)$/,
use: [{ loader: 'ifdef-loader', options: { CONDITION: false } } ],
exclude: /node_modules/ }
];
webpackConfig.rules version 2
[
{ test: /\.(js|jsx)$/,
use: [ 'babel-loader', { loader: 'ifdef-loader', options: { CONDITION: false } } ],
exclude: /node_modules/ },
...
];
What happens is the babel-loader
complains about a missing comma on the url: 'url/if/true'
line, when that line (or the other one, depending on the condition) should not even be getting to the babel-loader
, if my understanding of loaders is correct.
exact errors look like this:
ERROR in SyntaxError: path\to\folder \file.js: Unexpected token, expected "," (linenumber)
I can see that the ifdef-loader
appears to be getting applied correctly if I turn on verbose
, but the babel-loader
still fails after that.
OK, so I found that just including the commas at the end seems to stop it from complaining and allowing the build to succeed, but my question still remains as to why it's even getting the syntax that far.