You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gulp.task('browserify', function() {
var bundler = browserify({
entries: ['./src/js/app.js'], // Only need initial file, browserify finds the deps
transform: [reactify], // We want to convert JSX to normal javascript
debug: false, // Gives us sourcemapping
cache: {},
packageCache: {},
fullPaths: true // Requirement of watchify
});
var watcher = watchify(bundler);
return watcher
.on('update', function() { // When any files update
var updateStart = Date.now();
console.log('Updating!');
watcher.bundle() // Create new bundle that uses the cache for high performance
.pipe(source('main.js'))
// This is where you add uglifying etc.
.pipe(gulp.dest('./static/js/'));
console.log('Updated!', (Date.now() - updateStart) + 'ms');
})
.bundle() // Create the initial bundle when starting the task
.pipe(source('main.js'))
.pipe(gulp.dest('./static/js/'));
});
打包demo
PS:不包含第一步合并代码过程,此过程和开发环境选择有关
开发环境
开发环境,使用构建工具。关注的点是代码的模块化方式,从源码编译成可运行代码的过程等。本章主要讲的问题是发布流程所需要做的工作。
发布环境
代码发布会有几个流程
1.合并
将模块化的代码,合并编译。
1.
gulp-usemin
2.
requireJS
3.
browserify
4.
es6 import
gulp-usemin
,模版上写上合并的依赖requireJS
requireDemo使用rj合并require方式依赖的代码
browserify
browserifyDemo处理browserify的方式
es6 import
见: webpack打包es6 demo
配置webpack,编译合并代码
2.压缩
压缩的目的是减少包的大小,混淆代码。
3.静态加戳
为了解决浏览器缓存问题,文件变动时。主动改变js的戳。使浏览器能够获取最新的js。
4.模版戳替换
5.静态资源+模版提供使用
The text was updated successfully, but these errors were encountered: