我知道这似乎是一个巨大的步骤,但我真的建议您使用grunt。一旦掌握了它,这真的很简单。
这是速成课程:
- 安装NodeJS
安装Grunt CLI(只需在控制台/终端中输入此命令):
npm install -g grunt-cli
package.json
在项目的根目录中创建一个简单的文件:
{ “ name”:“ my-project-name”, “ version”:“ 1.0.0”, “ devDependencies”:{ “ grunt”:“〜0.4.2”, “ grunt-contrib-uglify”:“〜0.2.4”, “ grunt-contrib-watch”:“〜0.5.3” } }完成后,只需
npm install
在控制台(在项目的根目录中)中键入:。这将安装必要的grunt插件/依赖项(来自上面的软件包文件)。现在
gruntfile.js
,在项目的根目录中创建一个简单的目录(这是项目的一种配置):
module.exports = function(grunt){ grunt.initConfig({ // define source files and their destinations uglify: { files: { src: 'js/*.js', // source files mask dest: 'jsm/', // destination folder expand: true, // allow dynamic building flatten: true, // remove all unnecessary nesting ext: '.min.js' // replace .js to .min.js } }, watch: { js: { files: 'js/*.js', tasks: [ 'uglify' ] }, } }); // load plugins grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-uglify'); // register at least this one task grunt.registerTask('default', [ 'uglify' ]);};- 完成后,您只需要构建它即可。在控制台中输入:
grunt
或-更好-如果您键入执行以下命令-grunt将监视源文件中的更改,如果您更改了其中任何一个,它将自动生成它们:
grwatch手表-less
然后,您可以添加更多插件,例如:css缩小,css预处理器(less,sass,手写笔),jshint等。



