【发布时间】:2017-07-13 04:06:03
【问题描述】:
我想用 react 和其他构建我的 js 代码并将其缩小到一个文件。
效果很好,但我得到了 react 的开发版本
It looks like you're using a minified copy of the development build of React
现在我知道我需要添加NODE_ENV = production
但我尝试了很多方法,但构建仍然保持不变......
我尝试了如下所示的 envify,并像这样对其进行硬编码:
process.env.NODE_ENV = 'production';
但还是不好。
当我尝试添加 envify 变换时:
.transform(envify({
'NODE_ENV': 'production'
}))
我在构建时收到此错误:
TypeError Path must be a string.
有什么想法吗?
function bundleJs() {
const _browserify = browserify({
entries: [config.entry],
debug : false,
cache: {},
packageCache: {},
fullPaths: true,
extensions: ['.js']
});
_browserify.plugin(resolutions, ['*'])
.transform('envify', {global: true, _: 'purge', NODE_ENV: 'production'})
.transform(hbsfy)
.transform(babelify, {
only: /(app)|(frontend-app)/,
presets: ['es2015-without-strict', 'react']
})
.on('update', () => {
bundle();
gutil.log('Rebundle...');
})
.on('log', gutil.log);
function bundle() {
return bundler.bundle()
.on('error', handleError)
.pipe(source('init.js'))
.pipe(rename('bundle.js'))
.pipe(buffer())
.pipe(gulpif(env === 'production', uglify()))
.pipe(gulpif(env !== 'production', sourcemaps.init({ loadMaps: true })))
.pipe(gulpif(env !== 'production', sourcemaps.write('.')))
.pipe(gulp.dest(config.dist))
.pipe(browserSync.reload({stream:true}));
}
// run it once the first time buildJs is called
return bundle();
}
【问题讨论】:
-
你在你的应用中使用了 webpack bundler 吗?
-
没有 webpack,只有通过 gulp 浏览器化:|
-
哪个版本的反应?
-
已解决,谢谢! ://
标签: javascript reactjs gulp browserify