我目前正在尝试通过添加https://github.com/wangzuo/input-moment来增强我的ReactJS应用程序,我是通过import InputMoment from 'input-moment'
安装的,我使用// TODO: Get this to work.
require('app-module-path').addPath(__dirname);
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var babelify = require('babelify');
var watchify = require('watchify');
var sourcemaps = require('gulp-sourcemaps');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var gutil = require('gulp-util');
var notify = require('gulp-notify');
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
}
function buildScript(file, watch) {
var props = {
entries: ['./app/'+file],
debug: true,
transform: [babelify],
cache: {},
packageCache: {},
fullPaths: true
};
// watchify() if watch requested, otherwise run browserify() once
var bundler = watch ? watchify(browserify(props)) : browserify(props);
function rebundle() {
var stream = bundler.bundle();
return stream
.on('error', handleErrors)
.pipe(source(file))
// .pipe(streamify(uglify()))
.pipe(gulp.dest('./build/'));
}
// listen for an update and run rebundle
bundler.on('update', function() {
rebundle();
gutil.log('Rebundle ...');
});
// run it once the first time buildScript is called
return rebundle();
};
gulp.task('scripts', function() {
return buildScript('app.jsx', true);
});
gulp.task('sass', function () {
gulp.src('./assets/sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./build'));
});
gulp.task('sass:watch', function () {
gulp.watch('./assets/sass/**/*.scss', ['sass']);
});
gulp.task('default', ['scripts', 'sass', 'sass:watch']);
导入它。
但似乎我的自定义构建脚本不编译它,但尝试直接获取react样式版本。 [编辑:注意到React风格的html标签上的编译错误“意外令牌”)]
你能帮我修复我的构建脚本吗,所以包含未转换的文件也可以吗?
这是我的gulpfile.js:
{
"presets": ["es2015", "react"],
"plugins": [
"add-module-exports"
]
}
此外,我正在使用以下.babelrc:
{{1}}
到目前为止它工作正常并且我运行了很多模块,但这是第一个似乎在node_modules中未编译的模块。