browserify - require is called earlier as import statement -
i've got module m1
needs initialized before can import module m2
:
import * m1 'm1'; m1.init(...) import * m2 'm2';
i updated browserify
, switched 6to5ify
babelify
transformer. afterwards, require
calls in bundle got moved top:
... var _m1 = require('./m1'); var m1 = _interoprequirewildcard(_m1); var _m2 = require('./m2'); var m2 = _interoprequirewildcard(_m2); m1.init('init value'); ...
why require
calls moved top? can use es6 module import syntax import m2
after m1.init
called? can use require
directly
import * m1 'm1'; m1.init(...) const m2 = require('m2');
and get
var _m1 = require('./m1'); var m1 = _interoprequirewildcard(_m1); m1.init('init value'); var m2 = require('./m2');
but seems hack me.
can use es6 module
import
syntax importm2
afterm1.init
called?
irrespectively how babel transpiles code, answer is: no. spec dictates dependencies evaluated before module evaluated (§15.2.1.16.5).
that means import
declarations not evaluated when engine executes code. statically analyzed , information somehow added module, dependencies can evaluated before module evaluated.
even if found transpiler want, not spec compliant , code potentially break in future.
Comments
Post a Comment