700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > WebStorm学习笔记002---grunt-watch插件的使用-修改html css js文件实现自动编译更新

WebStorm学习笔记002---grunt-watch插件的使用-修改html css js文件实现自动编译更新

时间:2020-12-27 10:00:52

相关推荐

WebStorm学习笔记002---grunt-watch插件的使用-修改html css js文件实现自动编译更新

配置css和js文件发生变化就重新合并压缩css和js文件

package.json

{

"name": "AngularAndRequire",

"version": "0.1.0",

"description" : "AngularAndRequire1.0",

"author": "Mario.Li",

"devDependencies": {

"grunt": "~0.4.1",

"grunt-contrib-jshint": "~0.6.3",

"grunt-contrib-uglify": "~0.2.1",

"grunt-contrib-concat": "~0.1.1",

"grunt-contrib-watch": "~0.6.1",

"grunt-css": "~0.5.4"

}

}

Gruntfile.js

'use strict'

module.exports = function(grunt) {

// 配置

grunt.initConfig({

pkg : grunt.file.readJSON('package.json'),

concat : {

libs : {

src: ['frontend/libs/*.js', '!frontend/libs/require.js'],

dest: 'dest/libs.js'

},

custs: {

src: ['frontend/**/*.js', '!frontend/libs/*.js'],

dest: 'dest/cust.js'

},

css : {

src : ['frontend/styles/*.css', '!frontend/styles/index.css'],

dest : 'dest/index.css'

}

},

uglify : {

options : {

banner : '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'

},

buildlibs : {

src : 'dest/libs.js',

dest : 'dest/libs.min.js'

},

buildcusts : {

src : 'dest/cust.js',

dest : 'dest/cust.min.js'

},

},

cssmin : {

buildCss : {

src : 'dest/index.css',

dest : 'dest/index.min.css'

}

},

watch : {

all : {

files :['**/*.js', '**/*.css'],

tasks : ['concat', 'uglify', 'cssmin']

}

}

});

// 载入concat和uglify插件,分别对于合并和压缩

grunt.loadNpmTasks('grunt-contrib-watch');

grunt.loadNpmTasks('grunt-css');

grunt.loadNpmTasks('grunt-contrib-concat');

grunt.loadNpmTasks('grunt-contrib-uglify');

// 注册任务

grunt.registerTask('default', ['concat', 'uglify', 'cssmin', 'watch']);

};

参考资料:/itpinpai/article/details/48207493

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。