我正在尝试将Jotted javascript库与gulp-angular项目结合使用。库本身工作正常,但我试图包含库的Codemirror插件并遇到问题。当我尝试添加库并运行gulp serve
时,我收到此错误:
Error in parsing: "js/codemirror.js", Line 4: Unexpected reserved word
导致问题的一行如下:
import * as util from '../util.js'
我已经看到有些人使用babel来解决这类问题,但解决方案似乎超出了我的技能水平。
这是指插件的链接:
https://github.com/ghinda/jotted
我当前的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
}));
});
我目前的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');
});
堆栈跟踪
...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...
答案 0 :(得分:0)
我的猜测是你在ES5环境中使用import
语句运行代码,该环境不支持模块。
如果您在我怀疑的Node中运行它,则可以改为使用required
。