【发布时间】:2015-09-23 12:37:58
【问题描述】:
我正在做一个项目,我检查了左右下载的几个,我可以通过 Grunt。毫无疑问,这是我想使用的工具。
我已经设置了一个基本的 Grunt 文件,它可以让 livereload 工作,所以每当我更改我的 .html 文件时,页面都会刷新。
这一切都很好。请参阅下面的 sn-p,它为您概述了我当前的Gruntfile.js
'use strict';
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// The main entry point for the Grunt configuration file.
module.exports = function(grunt) {
// Load all the grunt tasks which are defined in the 'package.json' file.
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Initial grunt configuration.
grunt.initConfig({
// grunt-express configuration.
// Grunt-Express will serve files from the folder listed in the 'bases' property on the specified hostname
// and port.
express: {
all: {
options: {
bases: ['source'],
port: 8080,
hostname: "0.0.0.0",
livereload: true
}
}
},
// grunt-watch configuration.
// Grunt-Watch will monitor the project files.
watch: {
all: {
options: {livereload: true },
files: [
'**/*.html' // Refresh when any HTML file is being updated in any folder.
]
}
},
// grunt-open configuration.
// Grunt-Open will open your browser at the project url's.
open: {
all: {
// The port is loaded dynamically here through the 'express.all.options.port' property.
path: 'http://localhost:<%= express.all.options.port %>'
}
}
});
// Creates the various grunt tasks that needs to be executed.
grunt.registerTask('server', [
'express',
'open',
'watch'
]);
};
现在,在我的项目中,我正在使用 SASS (scss) 文件,我知道要编译这些文件,我需要一个名为 https://github.com/gruntjs/grunt-contrib-sass 的插件
在我的应用程序的目录结构中,我有一个“源”文件夹,当然我不想在其中有“css”文件。
那么,我怎样才能在我的 HTML 中放置一个指向将由 grunt 任务生成的 css 文件的链接?
我正在考虑将 scss 文件编译到临时文件夹中,但在我的 HTML 文件中,我不想放置“临时/...”链接。应该安装它们或其他东西。
有人知道如何实现我想要的吗?
亲切的问候
【问题讨论】:
-
您好,这个stackoverflow.com/questions/21859082/… 应该有帮助吗?
-
您好。感谢您的回答,但我不明白这对我有什么帮助。它只是给我有关如何设置手表和编译 sass 文件的信息。它没有提供有关如何使用临时文件夹以使 livereload 工作的任何信息。
标签: javascript gruntjs