Hi. I have kotlinjs amd module which generates js ...
# javascript
d
Hi. I have kotlinjs amd module which generates js file starting with
define(['exports', 'kotlin', ....
. However, to load it in npm I need to require 'amdefine' first, as described here http://requirejs.org/docs/node.html#nodeModules there should be a line like this at the top of the generated file
if (typeof define !== 'function') { var define = require('amdefine')(module); }
Is there any way to do it in kotlinjs?
f
Sounds like you need to change the module format in your build script to
commonjs
b
If you are going to use your compiled module in both, browser and nodejs
umd
would be better.
Use
commonjs
for nodejs like environments and
amd
and
plain
for browser like environments
d
umd
seems to be the only way to make kotlinjs work in both node and browser
(as I understand there are more options when using normal js and this difference is somewhat unintuitive with kotlinjs, so I might be not the first and not the last person to have these problems 🤔)
This is the
gradle.build
in case anyone is interested https://github.com/dkandalov/lsystem-js/blob/master/build.gradle