我想用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();
}发布于 2017-07-13 12:19:49
好吧,在我花了3个小时在这个代码上之后。
我注意到react的构建是从bower使用的,而不是从npm使用的。
在composer.json内部,我们在"browser“下有标识,即:
"react": "./bower_components/react/react.js",
"react-dom": "./bower_components/react/react-dom.js"我认为这直接指向了react dev build,所以这就是问题所在。
我只是简单地安装了npm,一切都运行得很好。
https://stackoverflow.com/questions/45071230
复制相似问题