Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

js-conditional-compile-loader

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-conditional-compile-loader

A javascript conditional compile loader for webpack. 一个javascript条件编译的webpack loader。

npmnpm
Version
1.0.8
Version published
Weekly downloads
51
-45.74%
Maintainers
1
Weekly downloads
 
Created
Source

js-conditional-compile-loader

A javascript conditional compile loader for webpack. You can easily output two different codes for debug or release environment with one source code.(一个javascript条件编译的webpack loader。可以很容易用一套代码实现debug和release环境输出两套不同js代码的。)

###Usage in JS files Just use it like this(这样用就行):

/*IFDEBUG Any js here FIDEBUG*/

Start with "/*IFDEBUG", end with"FIDEBUG*/", and js code in the center. you can use it any where in js files. (以“/*IFDEBUG”开头,以“FIDEBUG*/”结尾,中间是js代码。可以用在js文件的任意地方。)

samples:

$state.go('win', {dir: menu.winId /*IFDEBUG , reload: true FIDEBUG*/})

or

var tx = "This is app /*IFDEBUG of debug FIDEBUG*/ here";

or

/*IFDEBUG
	alert('Hi~');
FIDEBUG*/

Since it is designed by a js comment style, the code can run normaly even though the js-conditional-compile-loader is not used.(因为采用了js注释的形式,故即使不使用js-conditional-compile-loader,也不影响js代码的运行逻辑。)

###Setup npm i -D js-conditional-compile-loader

###Config in webpack You should change webpack config like this(你需要像这样修改webpack配置):

module: {
    rules: [
        {
            test: /\.js$/,
            include: [resolve('src'), resolve('test')],
            exclude: file => (
                /node_modules/.test(file) && !/\.vue\.js/.test(file)
            ),
            use: [
                //step-2
                'babel-loader?cacheDirectory',
                //step-1
                'js-conditional-compile-loader',
            ]
        },
        //other rules
    ]
}

##options

  • isDebug: {bool = [process.env.NODE_ENV == 'development']}

If isDebug === false, all the codes between "/*IFDEBUG" and "FIDEBUG*/" will be removed, otherwise the codes will be remained. (如果isDebug === false,所有"/*IFDEBUG" 和 "FIDEBUG*/"之间的代码都会被移除。 其他情况,这些代码则会被保留。)

Keywords

webpack

FAQs

Package last updated on 14 Jul 2018

Did you know?

Socket

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