Skip to content

TerserPlugin - exclude specific module / files #14750

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

Closed
lppedd opened this issue Jun 12, 2019 · 8 comments
Closed

TerserPlugin - exclude specific module / files #14750

lppedd opened this issue Jun 12, 2019 · 8 comments

Comments

@lppedd
Copy link

lppedd commented Jun 12, 2019

I haven't found a way to customize the TerserPlugin exclude option (and others).
Do you have any suggestion?

Terser is removing important functions from an external pure JavaScript library (bpmn-js) and I absolutely need to exclude it, while maintaining the build optimization.

@clydin
Copy link
Member

clydin commented Jun 12, 2019

In the future, please follow the issue template. It is quite difficult to provide assistance without the requested information.

The package is marked as being side effect free (https://github.com/bpmn-io/bpmn-js/blob/master/package.json#L38). If code is being removed, the most likely cause is that the package is not actually side effect free.
This line appears to confirm the suspicion: https://github.com/bpmn-io/bpmn-js/blob/master/lib/Viewer.js#L154

@clydin clydin closed this as completed Jun 12, 2019
@lppedd
Copy link
Author

lppedd commented Jun 12, 2019

@clydin Sorry about the template.
And yes, exactly that function is removed. Can I override this behavior?

@clydin
Copy link
Member

clydin commented Jun 12, 2019

This is actually an issue with the package. It is advertising itself as being side effect free when it is not. The CLI is acting appropriately given the information it is being provided by the package.

@lppedd
Copy link
Author

lppedd commented Jun 12, 2019

@clydin yeah, I know, I've been reading issues regarding Terser/UglifyJs behavior.
But what if I cannot modify the external library? I mean, TerserPlugin does offer a way to exclude files, by itself.

@clydin
Copy link
Member

clydin commented Jun 12, 2019

If you need a temporary workaround, you can remove the side effects field from the installed package. This would need to be done every time it is installed. For completeness, a post install script for the project is a common method to augment errant packages.

If the package is being imported into the application then there is no separate file to exclude. Only the final bundles are run through the minifier.

@lppedd
Copy link
Author

lppedd commented Jun 12, 2019

@clydin

If the package is being imported into the application then there is no separate file to exclude. Only the final bundles are run through the minifier.

Thanks for confirming that. I tought I was doing something wrong while debugging the builder.

a post install script for the project is a common method to augment errant packages.

I'll give this one a try, as I don't want to hand-edit the file every time.

Last question, if you can answer: the inherit function simply uses Object.create(...), what would be a side-effect free alternative (if any)?

if (typeof Object.create === 'function') {
  // implementation from standard node.js 'util' module
  module.exports = function inherits(ctor, superCtor) {
    ctor.super_ = superCtor
    ctor.prototype = Object.create(superCtor.prototype, {
      constructor: {
        value: ctor,
        enumerable: false,
        writable: true,
        configurable: true
      }
    });
  };
} else {
  // old school shim for old browsers
  module.exports = function inherits(ctor, superCtor) {
    ctor.super_ = superCtor
    var TempCtor = function () {}
    TempCtor.prototype = superCtor.prototype
    ctor.prototype = new TempCtor()
    ctor.prototype.constructor = ctor
  }
}

@clydin
Copy link
Member

clydin commented Jun 12, 2019

It's not actually the content of the function but rather the location of the call. Since the call is at the module level, importing the module will result in execution and cause some type of effect by simply importing the module.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants