fez-preprocess-loader
去除webpack打包由特殊注释标记的代码块
Last updated a year ago by furic-zhao .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fez-preprocess-loader 
SYNC missed versions from official npm registry.

fez-preprocess-loader

去除webpack打包时由特殊注释标记的代码块。用于移除webpack包中不需要的代码(例如mock数据等)。

示例:

业务逻辑

/* @if MOCK */
import mock from 'fezmock';
import mockData from './mock';
/* @endif */

function ApiSnapshot() {
  return new Promise((resolve, reject) => {
    /* @if MOCK */
    resolve(mock.mock(mockData).snapshot);
    return;
    /* @endif */

    Api.get(rankConfig.apiUrl.snapshotRange, params)
      .then((data) => {
        resolve(data);
      });
  });
}

配置webpack.config.js:

module.exports = {
  rules: [
    {
      test: /\.js$/,
      enforce: 'pre',
      exclude: /(node_modules|bower_components)/,
      use: [
        {
          loader: 'fez-preprocess-loader',
          options: {
            available: true //启用模块
          }
        }
      ]
    }
  ]
}

自定义开始和结束标记

module.exports = {
  rules: [
    {
      test: /\.js$/,
      enforce: 'pre',
      exclude: /(node_modules|bower_components)/,
      use: [
        {
          loader: 'fez-preprocess-loader',
          options: {
            available: true,
            start: 'START MOCK',
            end: 'END MOCK'
          }
        }
      ]
    }
  ]
}

Current Tags

  • 1.0.2                                ...           latest (a year ago)

3 Versions

  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 9
Last Month 12
Dependencies (1)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |