grunt简易打包

单纯是为了做一些小的页面,没必要引入vue/react,但是如果不压缩代码,显得很臃肿,所以引入grunt进行打包,记录一下。

项目结构:

js:放第三方js的一些压缩包。例如:jquery、jsencrypt

public:静态资源,图片之类的

Gruntfile.js

module.exports = function (grunt) {
  // 配置任务  
  grunt.initConfig({
    copy: {
      dist: {
        files: [
          { expand: true, cwd: './', src: ['public/**', 'js/**'], dest: 'dist/' }
        ]
      }
    },
    htmlmin: {
      dist: {
        options: {
          removeComments: true,
          collapseWhitespace: true,
          collapseInlineTagWhitespace: true,
          minifyCSS: true,
          minifyJS: true
        },
        files: {
          'dist/index.html': './index.html'
        }
      }
    }
  });

  // 加载插件任务  
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-htmlmin');

  // 注册任务  
  grunt.registerTask('build', ['copy', 'htmlmin']);
};

index.html

package.json

{
  "name": "demo",
  "version": "1.0.0",
  "description": "",
  "main": "Gruntfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "grunt": "^1.0.0",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-cssmin": ">=1.0.0",
    "grunt-contrib-htmlmin": "^2.1.0"
  }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值