Enable Closure when emitting an ES module.
See original GitHub issueWhen the ES module option is active:
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) }
the js file obtained trough fullOptJS
isn’t minified and project-opt.js
is only 3% smaller in size than project-fast-opt.js
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:25 (21 by maintainers)
Top Results From Across the Web
Closure compiler generates very long variable names in output
I am using the Closure compiler to compile a JavaScript file together with a couple of very simple ES6 modules. ... Is this...
Read more >Compiler Options - ClojureScript
A new option for emitting Google Closure Modules. Closure Modules supports splitting up an optimized build into N different modules.
Read more >Importing external ES6 modules - Google Groups
I have a project being built with the 20160315 version of the compiler, I use the closure compilers own module mechanism to group...
Read more >file-loader - webpack - JS.ORG
This will emit file.png as a file in the output directory (with the ... By default, file-loader generates JS modules that use the...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
This setting controls whether .js files are interpreted as ES modules or ... When TypeScript emits these to JavaScript files, it will emit...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gzm0 I’ve tried playing with it a bit.
To be honest I’m not sure if I know what I’m doing =); nevertheless, I managed to get the
JSC_INVALID_MODULE_PATH. Invalid module path "foo.js"
error.This error happens when we try to do
import from "file.js"
with theBROWSER
resolution mode enabled (which is by default, apparently) (described here).Changing the import to be
import from "./file.js"
(note the./
) makes the error go away.There is also the
NODE
resolution mode (it is also described at the page linked above):It will also want the
./
for the “local” imports, but it will go into thenode_modules
if there is no./
(/cc @armanbilge).I also tried another option: Transpiling Dynamic Import
Which is supposed to make closure “support” dynamic imports even when the output is lower than ECMASCRIPT_2020:
But it didn’t work for me - it complains:
I think this is why: https://github.com/google/closure-compiler/issues/3941
Not sure if this is helpful at all. I hope it is 😃
P.S. When running this:
it prints:
P.P.S.
I also tried
publishLocaling
the compiler and linking a simple project with these settings:Had to add this to the
ClosureAstTransformer
(as well as thecase ImportNamespace(binding, from) => ...
that @sjrd posted above):I think it worked (although I messed something and it looks like
fastLinkJS
andfullLinkJS
switched roles 😃 ). But in this small project there are no imports, so that doesn’t say anything.Also when I tried
.withModuleSplitStyle(ModuleSplitStyle.SmallestModules)
(hoping to get those imports) scalajs refused to link it:There’s apparently this thing now in GCC: https://github.com/google/closure-compiler/blob/be4a58341ee03da20fa2104ba90792745ccb3cfb/src/com/google/javascript/jscomp/CompilerOptions.java#L1164-L1171 We could try and set it to
false
inClosureLinkerBackend.closureOptions
and see what happens. 🤷♂️