项目作者: ystarlongzi

项目描述 :
A raw loader plugin for fis3.
高级语言: JavaScript
项目地址: git://github.com/ystarlongzi/fis3-hook-raw-loader.git
创建时间: 2017-04-20T12:57:32Z
项目社区:https://github.com/ystarlongzi/fis3-hook-raw-loader

开源协议:

下载


fis3-hook-raw-loader

一款基于 fis3 的 raw loader,允许在类 js 文件中嵌入其它文件的内容。

安装

  1. npm install fis3-hook-raw-loader

配置

  1. fis.hook('raw-loader');

用法

  1. -- page
  2. -- item.less
  3. -- item.es6
  4. -- item.png
  5. -- list.es6

假设存在如上目录结构,其中 item.less 内容如下:

  1. .title {
  2. font-size: 16px;
  3. strong {
  4. color: red;
  5. }
  6. }

item.es6 内容如下:

  1. const word = 'Hello world!';

然后,我们在 list.es6 中可以使用以下两种方法嵌入文件内容:

  • 使用 importrequire 关键字。(其中 !raw! 表示的是获取文件最初的、未做任何处理的内容)
  1. // list.es6
  2. import js from 'raw!./item';
  3. import css from '!raw!./item.less';
  4. const img = require('raw!./item.png');
  • 使用 __fis__raw() 方法。(!!!raw! 表示相同的含义)
    1. // list.es6
    2. const js = __fis__raw('!./item');
    3. const css = __fis__raw('!!./item.lss');
    4. const img = __fis__raw('!./item.png');

上面两种方式编译后的内容大致如下:

  1. // list.es6
  2. var js = "var word = 'Hello world!';";
  3. var css = ".title {\n font-size: 16px;\n\n strong {\n color: red;\n }\n}";
  4. var img = "data:image/png;base64,iVBORw0K......AAAElFTkSuQmCC";