babel-plugin-ember-data-packages-polyfill
raw JSON → 0.1.2 verified Sat Apr 25 auth: no javascript
A Babel plugin (v0.1.2) that transforms EmberData Packages API import statements (e.g., `import { attr } from '@ember-data/model'`) back to the legacy `DS.*` syntax for backward compatibility with older EmberData versions. It uses the @ember-data/rfc395-data mapping and is intended for use within Ember CLI apps and addons during the transition to the new packages. The plugin supports both default and named imports and works with Node 6+.
Common errors
error Cannot find module '@ember-data/rfc395-data' ↓
cause The dependency @ember-data/rfc395-data is not installed.
fix
npm install --save-dev @ember-data/rfc395-data
error Error: Babel plugin throw: Could not find mapping for '@ember-data/model' ↓
cause The plugin could not map a given import to a legacy path (possibly due to a new package not in the mapping data).
fix
Update @ember-data/rfc395-data to the latest version or add a custom mapping.
Warnings
gotcha Plugin requires @ember-data/rfc395-data to be installed as a dependency, otherwise it will fail to find mappings. ↓
fix Ensure @ember-data/rfc395-data is in your package.json dependencies.
gotcha The plugin only works with import statements; it does not transform dynamic require() calls. ↓
fix Use static import syntax for EmberData members.
deprecated This plugin is a transitional polyfill; as EmberData packages become universally supported, the plugin may become unnecessary. ↓
fix Migrate away from legacy DS syntax entirely when possible.
Install
npm install babel-plugin-ember-data-packages-polyfill yarn add babel-plugin-ember-data-packages-polyfill pnpm add babel-plugin-ember-data-packages-polyfill Imports
- babel-plugin-ember-data-packages-polyfill wrong
import plugin from 'babel-plugin-ember-data-packages-polyfill'; // This is a Babel plugin, not an importable modulecorrect// add to .babelrc plugins or ember-cli-build.js plugins
Quickstart
// In your .babelrc or ember-cli-build.js
{
"plugins": ["babel-plugin-ember-data-packages-polyfill"]
}
// Then in your source code, use new packages API:
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
// Will be transpiled to legacy syntax:
// import DS from 'ember-data';
// const Model = DS.Model;
// const attr = DS.attr;
// const belongsTo = DS.belongsTo;
// const hasMany = DS.hasMany;