babel-plugin-system-import-transformer
Babel plugin that replaces System.import with the equivalent UMD pattern
Transforms
System;
to
{ var global = window; if typeof globaldefine === 'function' && globaldefineamd global; else if typeof module !== 'undefined' && moduleexports && typeof require !== 'undefined' || typeof module !== 'undefined' && modulecomponent && globalrequire && globalrequireloader === 'component' ; else ; };
Installation
npm install babel-plugin-system-import-transformer
Add "system-import-transformer" to your plugins
argument or inside the plugins
options of your Gruntfile
.
babel: options: plugins: "system-import-transformer"
Configuration
Relative paths and Aliases
The babel's getModuleId option (if defined) is used for the AMD and Global Module import.
babel: options: moduleIds: true { var files = 'src/utils/serializer': 'utilsSerializer' ; return filesmoduleName || moduleName; } plugins: 'system-import-transformer'
AMD & CommonJS
When babel is configured to use AMD
or CommonJS
modules
babel: options: modules: 'amd' // ORbabel: options: modules: 'common' /* this is the default value for babel */
system-import-transformer
will omit the module type detection code and just insert the appropriate require statement wrapped with a Promise
.
// AMD { var global = window; global;}; // CommonJS { ;};