简体   繁体   English

包括带有角度gulp的Jotted的Codemirror插件

[英]Including Jotted's Codemirror plugin with angular gulp

I am trying to use the Jotted javascript library in conjunction with a gulp-angular project. 我正在尝试将Jotted javascript库与gulp-angular项目结合使用。 The library itself works fine, but I'm trying to include the library's Codemirror plugin and am running into issues. 库本身工作正常,但我正在尝试包含库的Codemirror插件并遇到问题。 When I try to add the library and run gulp serve , I get this error: 当我尝试添加库并运行gulp serve ,我收到此错误:

Error in parsing: "js/codemirror.js", Line 4: Unexpected reserved word

The line causing the issue looks like so: 导致问题的行看起来像这样:

import * as util from '../util.js'

I've seen a few people reference using babel to fix this sort of issue, but the solutions seem a tad beyond my skill level. 我见过一些人使用babel来修复这类问题,但解决方案似乎超出了我的技能水平。

Here's a link to the plugin: 这是插件的链接:

https://github.com/ghinda/jotted https://github.com/ghinda/jotted

My current server.js 我当前的server.js

'use strict';

var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var babel = require('gulp-babel');

var browserSync = require('browser-sync');
var browserSyncSpa = require('browser-sync-spa');

var util = require('util');

var proxyMiddleware = require('http-proxy-middleware');

function browserSyncInit(baseDir, browser) {
    browser = browser === undefined ? 'default' : browser;

    var routes = null;
    if (baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) {
        routes = {
            '/bower_components': 'bower_components'
        };
    }

    var server = {
        baseDir: baseDir,
        routes : routes
    };

    /*
     * You can add a proxy to your backend by uncommenting the line below.
     * You just have to configure a context which will we redirected and the target url.
     * Example: $http.get('/users') requests will be automatically proxified.
     *
     * For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.9.0/README.md
     */
    // server.middleware = proxyMiddleware('/users', {target: 'http://jsonplaceholder.typicode.com', changeOrigin: true});

    browserSync.instance = browserSync.init({
        startPath: '/',
        server   : server,
        browser: browser,
        host: '192.168.0.20',
        https: false,
        port   : parseInt(process.env.GULP_PORT) || 8684
    });
}

browserSync.use(browserSyncSpa({
    selector: '[ng-app]'// Only needed for angular apps
}));

gulp.task('serve', ['watch'], function () {
    browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]);
});

gulp.task('serve:dist', ['build'], function () {
    browserSyncInit(conf.paths.dist);
});

gulp.task('serve:e2e', ['inject'], function () {
    browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []);
});

gulp.task('serve:e2e-dist', ['build'], function () {
    browserSyncInit(conf.paths.dist, []);
});

var gulp = require('gulp');
var webserver = require('gulp-webserver');

gulp.task('webserver', function() {
  gulp.src('src')
    .pipe(webserver({
      host: '0.0.0.0',
      livereload: true,
      directoryListing: true,
      open: true
    }));
});

My current gulpfile.babel.js 我现在的gulpfile.babel.js

/**
 *  Welcome to your gulpfile!
 *  The gulp tasks are splitted in several files in the gulp directory
 *  because putting all here was really too long
 */

'use strict';

var gulp = require('gulp');
var wrench = require('wrench');
var babel = require('gulp-babel');

/**
 *  This will load all js or coffee files in the gulp directory
 *  in order to load all gulp tasks
 */
wrench.readdirSyncRecursive('./gulp').filter(function (file) {
    return (/\.(js|coffee)$/i).test(file);
}).map(function (file) {
    require('./gulp/' + file);
});


/**
 *  Default task clean temporaries directories and launch the
 *  main optimization build task
 */
gulp.task('default', ['clean'], function () {
    gulp.start('build');
});

Stack trace 堆栈跟踪

...standard build procedure...
[15:12:01] all files 224.05 kB
[15:12:01] Finished 'scripts' after 2.64 s
[15:12:01] Starting 'inject'...
[15:12:01] gulp-inject 10 files into index.html.
[15:12:02] [AngularFilesort] Error in plugin 'gulp-angular-filesort'
Message:
    Error in parsing: "js/codemirror.js", Line 4: Unexpected reserved word
[15:12:02] gulp-inject Nothing to inject into index.html.
[15:12:02] Finished 'inject' after 337 ms
[15:12:02] Starting 'watch'...
[15:12:02] Finished 'watch' after 93 ms
[15:12:02] Starting 'serve'...
[15:12:02] Finished 'serve' after 24 ms
...standard serve procedure...

My guess is that you run the code with the import statement on a ES5 environment, which does not support modules. 我的猜测是,您在ES5环境中使用import语句运行代码,该环境不支持模块。

If you run it in Node like I suspect, you can use required instead. 如果你像我怀疑的那样在Node中运行它,你可以使用required

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM