我使用以下 yeoman 生成器创建了一个 bootstrap-compass 项目:
https://www.npmjs.com/package/generator-bootstrap-compass
您可以在链接中看到文件结构。
如何正确地将 javascript 添加到这个 gruntfile 中?
gruntfile.js 看起来像这样:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: {
app: 'app'
},
connect: {
options: {
port: 9000,
livereload: 35729,
// Change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= config.app %>/public'
]
}
},
},
watch: {
options: {
livereload: true,
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= config.app %>/public/{,*/}*.html',
'<%= config.app %>/public/css/{,*/}*.css',
'<%= config.app %>/public/images/{,*/}*'
]
},
compass: {
files: ['**/*.{scss,sass}'],
tasks: ['compass:dev']
},
},
compass: {
dev: {
options: {
sassDir: ['app/src/stylesheets'],
cssDir: ['app/public/css'],
environment: 'development'
}
},
prod: {
options: {
sassDir: ['app/src/stylesheets'],
cssDir: ['app/public/css'],
environment: 'production'
}
},
}
});
// Load the plugin
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-connect');
// Default task(s).
grunt.registerTask('default', ['connect:livereload', 'compass:dev', 'watch']);
// prod build
grunt.registerTask('prod', ['compass:prod']);
};
编辑:
解决方案:
我刚刚将 grunt-contrib-uglify 和以下代码添加到我的 gruntfile.js 以压缩我项目中的任何 js 代码:
uglify: {
all: {
files: {
'<%= config.app %>/public/js/bootstrap.min.js': ['<%= config.app %>/src/javascripts/bootstrap.js']
}
},
}