package.json
grunt.initConfig
grunt-contrib-watch
grunt-contrib-connect
始めましょうgrunt.registerTask
ファイルを作成します:これは、プロジェクトとその依存関係を定義します。 それらをインストールするにはを実行します
ファイルのコピーとビルドクリーンアップnpm install -g grunt-cli
package.json
ソースコードを維持し、ファイルを個別にビルドします。
{ "name": "grunt_tutorial", "description": "Grunt setup for web development.", "author": "Landon Schropp (http://landonschropp.com)", "dependencies": { "grunt": "0.x.x", "grunt-autoprefixer": "0.2.x", "grunt-contrib-clean": "0.5.x", "grunt-contrib-coffee": "0.7.x", "grunt-contrib-connect": "0.4.x", "grunt-contrib-copy": "0.4.x", "grunt-contrib-cssmin": "0.6.x", "grunt-contrib-jade": "0.8.x", "grunt-contrib-jshint": "0.6.x", "grunt-contrib-stylus": "0.8.x", "grunt-contrib-uglify": "0.2.x", "grunt-contrib-watch": "0.5.x" }, "engine": "node >= 0.10" }
npm install
これにより、ファイルが
からのコピーがコピーされ、ディレクトリがクリーニングされます。 実行
。
Gruntfile.js
module.exports = function(grunt) { grunt.initConfig({ copy: { build: { cwd: 'source', src: [ '**', '!**/*.styl', '!**/*.coffee', '!**/*.jade' ], // Exclude compiled files dest: 'build', expand: true }, }, clean: { build: { src: [ 'build' ] }, stylesheets: { src: [ 'build/**/*.css', '!build/application.css' ] }, scripts: { src: [ 'build/**/*.js', '!build/application.js' ] }, }, }); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.registerTask('build', ['clean:build', 'copy']); };
結論source
build
この合理化されたガイドは、堅牢で効率的なグラントベースのビルドプロセスを構築するための基盤を提供します。 ワークフローをさらにカスタマイズするために、広大なGruntプラグインエコシステムを探索してください。
以上がグラントで素晴らしいビルドスクリプトを書くの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。