-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Description
Steps to reproduce this issue
- Initialize the project structure:
$ cd <base>
$ mkdir test
$ cd test
$ yarn init
$ yarn add --dev webpack webpack-cli
$ mkdir src- Create
src/index.js:
function component() {
const element = document.createElement('pre');
element.innerHTML = ['Hello', 'webpack', '5 cube is equal to ' + cube(5)].join('\n\n');
return element;
}
document.body.appendChild(component());- Create
src/math.js:
export function square(x) {
return x * x;
};
export function cube(x) {
return x * x * x;
};- Create
webpack.config.js:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/index.js',
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new webpack.ProvidePlugin({
cube: ['./math.js', 'cube'],
}),
],
mode: 'production',
optimization: {
runtimeChunk: true,
},
};- Build the bundle:
$ yarn webpack-
Expected Result:
ONLY thecube()function is included indist/main.bundle.js -
Actual Result:
BOTH thecube()and thesquare()functions are included.
Environment
- webpack - 5.14.10
- node - 15.5.0
- OS - macOS Big Sur
Reactions are currently unavailable