Giter Site home page Giter Site logo

js-macro-compile's Introduction

js-macro-compile

利用自定义宏,在特定的场景下,删除没有覆盖到的分支代码。

usage

安装它:

npm install js-macro-compile --save

在node.js中使用它:

var jsMacroCompile = require('js-macro-compile');
var code = require('fs').readFileSync(filename, 'utf8');
var config = {
    mobile: 1
};
code = jsMacroCompile(code, {config: config});
console.log(code);

test

npm install
npm run example

result

环境配置:

var config = {
    mobile: 1,
    ios: 1,
    android: {
        chrome: 1,
    }
};

源代码:

define(
    function (require) {
        // simple
        if (EC_DEFINED('mobile')) {
            console.log('mobile');
        }
        else {
            console.log('pc');
        }

        // no else
        if (EC_DEFINED('mobile') && EC_DEFINED('ios')) {
            console.log('ios');
        }

        // multi macros in a if condition
        if (EC_DEFINED('mobile') && EC_DEFINED('android.chrome')) {
            var test = require('chrome');
        }
        else {
            var test2 = require('pc2');
        }
    }
);

预编译之后:

define(function(require) {
        console.log("mobile");
        console.log("ios");
        var test = require("chrome");
        var test = require("hammer");
});

目前只满足一些简单的宏定义。

js-macro-compile's People

Contributors

hushicai 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.