Open exoego opened 6 years ago
I am trying to use scalajs-bundler to bundle app and node_modules into one file, targeting to node.js runtime.
If you target the Node.js runtime, you shouldn't even bundle. Node.js can load the non-bundled CommonJS module in the regular fastopt.js.
Bundling is for browsers. It doesn't make sense for Node.js.
Ah, I see why it generates var exports = window
.
I expected webpack, not only to bundle dependencies, but also to minify them, for environment where sizes matter. More specifically, it is AWS Lambda and similar Function as a Service. Minifying node_module is not uncommon for the domain. E.g., https://github.com/serverless/serverless-optimizer-plugin is for such purpose.
Webpack can minimize but you need to configure it. E.g. with the uglify plugin
@cquiroz Thanks for let me know the uglify plugin.
Can we use such plugin with scalajs-bundler, without fixing loader script (var exports = window
)?
Those are independent concepts. I think the window call is very much fixed on the creation of webpack’s config for scala js
any idea what can cause this error to occur? I randomly get it also. I usually need to delete my target directories in my sbt project and rebuild.
In my chrome browser console, it says:
Uncaught TypeError: Cannot read property 'require' of undefined at client-fastopt-loader.js:3
and all there is in that file is:
var exports = window;
exports.require = window["ScalaJSBundlerLibrary"].require;
I am trying to use scalajs-bundler to bundle app and node_modules into one file, targeting to node.js runtime. However, when the bundled file (
...-bundle.js
) is invoked on node. a ReferenceError (window is not defined
) occurs.Environment
What happens
In the above circrumstance, the generated
foo-opt-loader.js
is like belowI believe these lines causes
window is not defined
error.I referred Output- Webpack and tried several
output.libraryTarget
such asvar
(default of scalajs-bundler),this
,commonjs
andcommonjs2
.It looks like
foo-opt-library.js
respectsoutput.libraryTarget
config and changes its form. However,foo-opt-loader.js
does not respect the config and keepvar exports = window
line.Any ideas?