跳到主要內容

GRUNT SMARTER AND AUTOMATE - Grunt watch

We have do something smarter and automate with grunt after JS optimization. Let's install "grunt-contrib-watch" that run predefined tasks whenever watched file patterns are added, changed or deleted.


How to install ?

1. Run "npm install grunt-contrib-watch --save-dev" in ur project location.
2. Add "grunt.loadNpmTasks('grunt-contrib-watch');" in Gruntfile.js loated in ur project location.

Gruntfile.js - The sample use Closure complier to optimize JS file. »see more
module.exports = function(grunt) {
    grunt.initConfig({
        file: {
            min: {
                dest: 'js/opt/min.js',
                src: [
                    'js/jquery.tools/overlay/overlay.js',
                    'js/jquery.tools/scrollable/scrollable.js',
                ]
            }
        },
        'closure-compiler': {
            min: {
                closurePath:'/Library/closure/',
                js: ['<%= file.min.src %>'
                ],
                jsOutputFile: '<%= file.min.dest %>',
                noreport: true,
                options: {
                    compilation_level: 'SIMPLE_OPTIMIZATIONS',
                    //compilation_level: 'ADVANCED_OPTIMIZATIONS',
                    //compilation_level: 'WHITESPACE_ONLY',
                    warning_level:"DEFAULT"
                }
            }
        },
        watch: {
            min: {
                files: ['<%=file.min.src%>'],
                tasks: ['closure-compiler:min'],
                options: {
                    spawn: false,

                },
            }
        }  
    });
    grunt.loadNpmTasks('grunt-closure-compiler');
    grunt.loadNpmTasks('grunt-contrib-watch');
};


How to run ?


grunt watch or grunt watch:min



參考自 https://npmjs.org/package/grunt-contrib-watch

留言

這個網誌中的熱門文章

Indexed Database API - Initail

As a front web developer, I could create UI faster or Optimize file to load page faster. But it hard to faster response time form server however 80-90% of the end-user response time is spent on the frontend. Nowadays we could use the Indexed Database API, or IndexedDB to reduce the request times. Less request times, less response time. What is IndexedDB ? IndexedDB is web browser standard interface for a local database of records holding simple values and hierarchical objects. IndexedDB was initially proposed by Oracle in 2009./* wiki */ What browsers would support IndexedDB ? Most browsers of hybrid devices support it exclude IE9-, Safari 7-,iOS Safari 7.1-, Opera Mini, Android Browser 4.3-./* caniuse.com */ When shall we use IndexedDB ? Save Money on web hosting Data index sort Data keyword search Keep data for period of time How to start it? //*************************************************************** //initDB //{Object}, {data: dbName, objectStore: storeName, ...

最近設計的一組icon..太有APPLE風格被打槍了

jQuery 的slideToggle太好用了

$ ( ".collapse" ) .each ( function ( index, value ) { $ ( this ) . click ( function ( evt ) { evt.preventDefault ( ) ; //prevent the default click event of the anchor tag. var target = $ ( this ) .attr ( "data-toggle" ) ; $ ( "." + target ) .slideToggle ( ) ; } ) ; } ) ; http://code-tricks.com/create-a-common-toggler-for-div-using-jquery/