Socket
Socket
Sign inDemoInstall

babel-plugin-bem-import

Package Overview
Dependencies
104
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-bem-import

BEM imports resolver


Version published
Maintainers
2
Install size
12.8 MB
Created

Readme

Source

BEM import

BEM-entities auto resolver for custom import strings.

import Block from 'b:block';
import Block from 'b:block m:modName';
import Block from 'b:block m:modName=modVal1|modVal2';
import BlockElem from 'b:block e:elem';
import BlockElem from 'b:block e:elem m:modName';
import BlockElem from 'b:block e:elem m:modName=modVal1|modVal2';

Install

npm i -D babel-plugin-bem-import

Babel version

For babel-7 use babel-plugin-bem-import@2 For babel-6 use babel-plugin-bem-import@1

Usage

.babelrc

{
  "plugins": [
    ["bem-import", {
      "naming": "react",
      "levels": [
        "./common.blocks",
        "./desktop.blocks"
      ],
      "techs": ["js", "css"]
    }]
  ]
}

Options

  • naming: bem-naming overrides
  • levels : paths to components declarations
  • techs : list of techs extensions for require in runtime, ['js'] by default
  • techMap : mapping of techs to extensions. Example: { 'js' : ['react.js', 'react.ts', 'react.es'], 'css' : ['post.css'] }
  • langs : list of langs in which resloves '.i18n' tech
  • i18n

    .i18n - represent special technology that provides the opportunity to localize components.

    For correct working you need to install bem-i18n inside your project.

    npm i -S bem-i18n
    

    On file system:

    blocks/Attach/
    ├── Attach.react.js
    ├── Attach.i18n
    │   ├── en.js
    │   ├── ru.js
    │   └── tr.js
    └── Attach.spec.js
    

    en.js, ru.js and tr.js are keysets and should be common.js modules.

    $ cat blocks/Attach/Attach.i18n/tr.js
    module.exports = {
        "Attach": {
            "button-text": "Dosya seç",
            "no-file": "dosya seçilmedi"
        }
    };
    

    inside Attach.react.js:

    import i18n from `b:Attach t:i18n`
    
    console.log(i18n('button-text')) // → Dosya seç
    

    babel-import transpiles such code to

    var i18n = (function() {
        var core = require('bem-i18n');
    
        if (process.env.BEM_LANG === 'ru') {
            return core().decl(require('../Attach.i18n/ru'))('Attach')
        }
    
        if (process.env.BEM_LANG === 'en') {
            return core().decl(require('../Attach.i18n/en'))('Attach')
        }
    
        if (process.env.BEM_LANG === 'tr') {
            return core().decl(require('../Attach.i18n/tr'))('Attach')
        }
    })();
    
    console.log(i18n('button-text')) // → Dosya seç
    

    process.env.BEM_LANG is need to be defined. ru, en and tr are taken from langs option.

    License MIT

Keywords

FAQs

Last updated on 27 Sep 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc