google / google/closure-compiler

Add an Option To Prevent Rewriting Import/Require Statements for Specific Modules

Open
#1,382 10 comments 5 reactions 0 assignees View on GitHub
help wanted
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

When working with module systems, there needs to be some way to designate that certain import statements are intended to be runtime imports rather than compile time. This will only apply to CommonJS modules currently until such a time as the compiler recognizes and rewrites the [WhatWG Loader Import Statements](https://whatwg.github.io/loader/). See
- https://groups.google.com/forum/#!searchin/closure-compiler-discuss/externalRequire/closure-compiler-discuss/4SpP-o7HKBk/h6NYu1eMIcMJ
- https://gist.github.com/Kegsay/2cb999a78dbd2b8bda95
- #1380

The consensus around this discussion seems to be that this should be a flag, rather than an annotation.

The flag should meet the following criteria:
- The same flag should work for ES6 and CommonJS modules
- It MUST take into account all of the following cases:
- The `--module` flags are used and thus both the import and export statements are provided to the compiler as input but divided into separate outputs for runtime loading
- The export statement is not provided to the compiler and is therefore external code. This covers core NodeJS module imports.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.