aui / tmodjs

前端模板外置解决方案

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

结合babelify使用的时候,runtime.js会报错

zhuowenli opened this issue · comments

结合 babelify 使用的时候,babelify 会重新编译代码,导致 runtime.jsthis指向undefined:

var String = this.String;

建议改成:

var String = window.String;

你是绿箭?这个项目两年没有维护了,不建议使用在正式项目中…

模板可以考虑采用基于 webpack 的方案

@aui 这个项目目前么有人维护了吗?

commented

暂时可以用gulpgulp-replace插件,把这个this.String换成window.String

var String = this.String;
// 修改为:
var String = window.String;

gulp-replace插件

gulp.task('tpl', function() {
  gulp
    .src('src/template/**/*.html')
    .pipe(
      tmodjs({
        templateBase: 'src/template',
        runtime: 'htmlTpl.js',
        compress: false
      })
    )
    // 主要是this  →  window
    .pipe(replace('var String = this.String;', 'var String = window.String;'))
    .pipe(gulp.dest('src/js'));
});