tmodjs icon indicating copy to clipboard operation
tmodjs copied to clipboard

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

Open zhuowenli opened this issue 9 years ago • 4 comments

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

var String = this.String;

建议改成:

var String = window.String;

zhuowenli avatar Feb 18 '16 10:02 zhuowenli

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

aui avatar Feb 18 '16 10:02 aui

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

aui avatar Feb 18 '16 10:02 aui

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

stuxt avatar Sep 07 '16 08:09 stuxt

暂时可以用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'));
});

malun666 avatar Apr 21 '18 08:04 malun666