Last active
October 4, 2016 04:59
-
-
Save kenichi-odo/718baf9cf11318e9a5e00dd25e7aab02 to your computer and use it in GitHub Desktop.
gulpを使ってJavaScriptをwebpackでビルドしてForce.comにデプロイする ref: http://qiita.com/kenichi_odo/items/8be8e773cfb98b0bb1bf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd deploy_salesforce_using_gulp_webpack-1.0 | |
sudo npm install gulp gulp-jsforce-deploy gulp-watch gulp-webpack gulp-webpack gulp-zip jquery --save-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Force.comのログインユーザ名とパスワードの設定 | |
process.env.SF_USERNAME = 'xxx@xxx.xxx'; | |
process.env.SF_PASSWORD = 'xxxxxxxx'; | |
// moduleのロード | |
var gulp = require('gulp'); | |
var webpack = require('gulp-webpack'); | |
var zip = require('gulp-zip'); | |
var jsforce = require('gulp-jsforce-deploy'); | |
// ターミナルからgulp watchを実行した時、 | |
// main.jsの変更を監視する | |
gulp.task('watch', function() { | |
// 変更があったらデプロイ開始 | |
gulp.watch('main.js', ['deploy']); | |
}); | |
// デプロイをする前にwebpackでビルドする | |
gulp.task('deploy', ['webpack'], function() { | |
// loginUrlは適宜書き換えてください | |
gulp.src('./pkg/**', { base: "." }) | |
.pipe(zip('pkg.zip')) | |
.pipe(jsforce({ | |
username: process.env.SF_USERNAME, | |
password: process.env.SF_PASSWORD, | |
loginUrl: 'https://test.salesforce.com' | |
})); | |
}); | |
// ビルドした後、Test配下のbundle.jsとbundle.js.mapをzipにし | |
// staticresources内に格納する | |
gulp.task('webpack', ['build'], function() { | |
return gulp.src('./build/Test/*').pipe(zip('Test.resource')).pipe(gulp.dest('pkg/staticresources')); | |
}); | |
// webpackを実行しmain.jsをjQuery使用可能にしたbundle.jsに変換 | |
// デバッグできるようにsource mapを吐き出す | |
// returnで処理を同期 | |
gulp.task('build', function() { | |
return gulp.src('main.js').pipe( | |
webpack({ | |
entry: './main.js', | |
output: { | |
filename: 'bundle.js' | |
}, | |
devtool: 'source-map' | |
}) | |
).pipe(gulp.dest('./build/Test')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment