如何在榆树中进行实时重装/自动页面刷新?

时间:2016-10-07 11:31:42

标签: elm

我正在尝试从here.学习elm编程语言而且每次稍微改动都会让我手动执行页面刷新。

我看到榆树反应堆不再支持实时回放了。但是,下一个版本我能做些什么呢?

2 个答案:

答案 0 :(得分:3)

我通常使用elm-live

如果您只是将Elm编译为js,它非常简单易用。

答案 1 :(得分:1)

<强>解决! - gulp magic节省了一天!

(此解决方案仅适用于Chrome)以下是我所做的 - 基于on this :(感谢janiczek !! :))

  1. 在根目录中添加名为gulpfile.js
  2. 的新文件
  3. 将此内容粘贴到:
  4. <强> gulpfile.js:

    evar gulp = require('gulp');
    var elm  = require('gulp-elm');
    var concat = require('gulp-concat');
    var plumber = require('gulp-plumber');
    var livereload = require('gulp-livereload');
    
    var path = ['*.elm']; // here you adjust the path according with your needs.
                          // For ex: 'scr/**/*.elm' - maps to every folder and file nested inside the src folder.
    gulp.task('elm-init', elm.init);
    
    gulp.task('elm', ['elm-init'], function(){
      return gulp.src(path)
        .pipe(plumber())
        .pipe(elm())
        .pipe(concat('elmapp.compiled.js'))
        .pipe(gulp.dest('js'))
        .pipe(livereload());
    });
    
    gulp.task('default',['watch']);
    
    gulp.task('watch', function(){
      livereload.listen();
      gulp.watch(path,['elm']);
    });
    
    1. 如果不运行,您必须全局安装gulp:

       npm install gulp -g
      
    2. 安装gulp依赖项:

       npm install gulp-elm gulp-concat gulp-plumber gulp-livereload
      
    3. 安装this extension: (chrome only)
    4. 运行elm-reactor并在Chrome中打开您的页面。
    5. 从终端内部,根目录(或gulpfile.js所在的位置)运行:gulp
    6. 打开elm页面选项卡,按Chorme Extension上的LiveReload按钮。如下所示,并确保它说:
    7. enter image description here

      1. 你很高兴! :)
      2. Elm编译器不喜欢.js个文件,所以你仍会看到2个错误。别理他们。对我来说,其他一切都按预期工作。