Comments (5)
Actually only string liberals are currently supported as an argument at the
moment. Variables #4, string concatenation expressions and template
liberals are not supported. That's because CommonJS bundlers, most namely
webpack and browserify, analyze the code and require a string literal to be
used, so that they can determine the imported modules during the
compilation step (at least that was how things worked when I implemented
this).
Which bundling system are you using?
If this CommonJS limition doesn't exist any more then we should try adding
support for this. At the moment we should be able to add support for this
for AMD and Global transformation targets.
Thodoris Greasidis
from babel-plugin-system-import-transformer.
@thgreasi I'm transpiling to CommonJS. As a workaround I'm just resolving a promise with a require
call, which seems to be working just fine:
Bluebird.resolve(require(`./pages/${name}/route`))
I'm using [email protected]
so I'm not sure if this is supported in webpack 1, but it recognizes that I'm requiring based on an expression and is using a regex to resolve those imports:
[268] ./app/pages ^\.\/.*\/route$ 239 bytes {0} [built]
+ 645 hidden modules
from babel-plugin-system-import-transformer.
Thanks for the details. I will check it out as soon as I find some time.
Expressions were not supported back in webpack 1 so I never bothered. Of
course this isn't going to be working for browserify users, which as far as
I know need string literals as require parameters.
Thodoris Greasidis
from babel-plugin-system-import-transformer.
Just released v2.4.0 that should try to transform any expression.
Until now we checked if it was an actual string literal.
Of course the result might not work on all environments, but your webpack2 use case should now work.
Have fun (hopefully) and please, please, please, report back whether it worked for you.
from babel-plugin-system-import-transformer.
@thgreasi awesome thanks! It's working swimmingly 👍
from babel-plugin-system-import-transformer.
Related Issues (14)
- Add support for babel 6 HOT 8
- Support `import` function HOT 2
- Add support for `require.ensure()` target HOT 1
- drop component support
- make commonjs use require.ensure by default
- System is not defined HOT 2
- Working with babel 7 HOT 5
- When compiling AMD modules and the moduleIds flag is set, the wrong moduleId is inserted HOT 2
- only client side? HOT 3
- Cannot transform when module name was a variant rather than literal HOT 4
- Server-side/CommonJS loading time increase HOT 19
- Problem accessing module HOT 19
- ReferenceError: self is not defined HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-system-import-transformer.