zoukankan      html  css  js  c++  java
  • 加载器中的预编

      if (_type == "js") {//js预编译
                        var _script = "_define(function(exports,module){
    ";
                        _script += "var $parent = "" + _basePath + "";
    ";
                        _script += data.replace(/require(/g, "_require($parent,");
                        _script += ";
    });" + "//@ sourceURL=" + _absUrl(path);
                        _moudle = window["eval"](_script);
    }

    上面这段程序会把下面的代码

    exports.txt = "hello word";
    var rep=require("./js/moule");
    module.exports={
        "name":"张三"
    }

    预编译为

    _define(function(exports,module){
    var $parent = "";
    exports.txt = "hello word";
    var rep=_require($parent,"./js/moule");
    module.exports={
        "name":"张三"
    };
    });//@ sourceURL=http://localhost:63342/jiaocheng/moudle.js

    1.加上了_define(function(exports,module){ 

    2.var rep=require("./js/moule"); 变为了var rep=_require($parent,"./js/moule");

    3.加上了var $parent = "";  $parent 是 当前js 的路径,因为 当前js在根目录 所以$parent为空

  • 相关阅读:
    BigDecimal 和NumberFormat及 获取总页数的应用
    格式化小数点和百分号 DecimalFormatter
    Vue 项目开发
    js 对象补充
    Vue 实例成员
    Vue 指令
    Vue 介绍
    Vue
    request-html
    Python 中的经典类新式类
  • 原文地址:https://www.cnblogs.com/blowfish/p/3785215.html
Copyright © 2011-2022 走看看