I need to do something like:
if (condition) {
import something from 'something';
}
// ...
if (something) {
something.doStuff();
}
The above code does not compile; it throws SyntaxError: ... 'import' and 'export' may only appear at the top level
.
I tried using System.import
as shown here, but I don't know where System
comes from. Is it an ES6 proposal that didn't end up being accepted? The link to "programmatic API" from that article dumps me to a deprecated docs page.
package.json
; mygulpfile
then checks if that dependency exists before performing some build steps. - ericsocowebpack
andbabel
to transpile es6 to es5. Projects likewebpack-rewire
and similar are not to help here - github.com/jhnns/rewire-webpack/issues/12 . One way to set the test doubles OR to remove problematic dependencies could be the conditional import. - Amio.iowebpack
is used to convert stylesheets into modules that insert the relevant styles into the DOM when they're imported) but the module also needs to run outside of the browser (e.g. for unit testing). - Jules(condition)
can be resolved at build time then different preprocessed versions of the product can be prepared and the condition removed. E.g.,(condition)
is meant to distinguish front end (browser) vs back end (common js). Then the condition statement becomes unnecessary. - Craig Hicks