Webpack 2.2.0
I include/exclude file/folder in my config, but webpack keeps bundling that was excluded:
the folder structure
src/
index.js // entry point
server/
test.js // file for testing
build/
webpack.config.js
const path = require('path')
const SRC = path.resolve(process.cwd(), './src')
const BUILD = path.resolve(process.cwd(), './build')
module.exports = {
context: SRC,
entry: {
main: './'
},
output: {
path: BUILD,
filename: '[name].bundle.js',
publicPath: '/assets/'
},
module: {
rules: [{
test: /\.jsx?/,
include: SRC,
exclude: path.resolve(process.cwd(), './server’), // even explicit excluding changes nothing
loader: 'babel-loader'
}]
}
}
./src/index.js
import func from ‘../server/test.js’ // this must not be imported
func() // working
./server/test.js
export default function () { console.log(`I’m in the bundle`) } // this is being executed
I see the message in the browser console.
And the answer is if you include/exclude
something in the webpack config it won't be transformed by the loader but it will be imported into the bundle. To completely exclude something from bundling you need to use module.noParse
option: https://webpack.js.org/configuration/module/#module-noparse
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With