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

The webpack.ProvidePlugin does not tree shake code as documented #12441

Closed
zerustech opened this issue Jan 18, 2021 · 5 comments · Fixed by #15627
Closed

The webpack.ProvidePlugin does not tree shake code as documented #12441

zerustech opened this issue Jan 18, 2021 · 5 comments · Fixed by #15627

Comments

@zerustech
Copy link

zerustech commented Jan 18, 2021

Steps to reproduce this issue

  1. Initialize the project structure:
$ cd <base>
$ mkdir test
$ cd test
$ yarn init
$ yarn add --dev webpack webpack-cli
$ mkdir src
  1. 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());
  1. Create src/math.js:
export function square(x) {
    return x * x;
};

export function cube(x) {
    return x * x * x;
};
  1. 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,
    },
};
  1. Build the bundle:
$ yarn webpack
  1. Expected Result:
    ONLY the cube() function is included in dist/main.bundle.js

  2. Actual Result:
    BOTH the cube() and the square() functions are included.

Environment

  • webpack - 5.14.10
  • node - 15.5.0
  • OS - macOS Big Sur
@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member

bump

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@vankop
Copy link
Member

vankop commented Sep 15, 2021

Closing because of inactivity. Feel free to report new issue with reproducible repo.

@vankop vankop closed this as completed Sep 15, 2021
@alexander-akait
Copy link
Member

Still valid

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

Successfully merging a pull request may close this issue.

5 participants