Coder Social home page Coder Social logo

webpack-bem-loader's Introduction

Webpack BEM loader

Webpack loader for bem-react-core

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 webpack-bem-loader

Usage

In your webpack.config.js.

Webpack 1

  // setting for bem-loader
  bemLoader: {
    naming: 'react',
    levels: ['./pathToBlocks'],
    // OR:
    // levels: {
    //     './pathToBlocks': {
    //         default: true,
    //         scheme: 'nested',
    //         naming: 'origin'
    //     }
    // },
    techs: ['js', 'css'],
    techMap: {
        js : ['react.js']
    },
    langs: ['ru', 'en']
  },

Webpack 2

// setting for bem-loader
module: {
    rules: [
        {
            test : /\.react\.js$/,
            loader: 'webpack-bem-loader',
            options: {
                naming: 'react',
                levels: ['./pathToBlocks'],
                // OR:
                // levels: {
                //     './pathToBlocks': {
                //         default: true,
                //         scheme: 'nested',
                //         naming: 'origin'
                //     }
                // },
                techs: ['js', 'css'],
                techMap: {
                    js : ['react.js']
                },
                langs: ['ru', 'en']
            }
        }
    ]
}

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.

    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.js:

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

    webpack-bem-loader transpiles such code to

    var i18n = (function() {
        var core = require('/absolute-path-to/webpack-bem-loader/generators/i18n/core');
    
        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 MPL-2.0

webpack-bem-loader's People

Contributors

awinogradov avatar remnev avatar veged avatar yar-usenko avatar yeti-or avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.