【发布时间】:2016-08-11 06:32:50
【问题描述】:
我的项目结构是这样的:
my_project
|-- css
| -- main.css
|-- css-dev
| -- main.css
|-- node_modules
| -- bootstrap
| -- dist
| -- css
| -- bootstrap.css
|-- package.json
`-- Gruntfile.js
而我的Gruntfile.js 是这样的:
module.exports = function (grunt) {
var processorArray = [
require('postcss-import')(),
require('cssnano')()
];
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
postcss: {
options: {
processors: processorArray
},
dist: {
files: [{
expand: true,
cwd: 'css-dev/',
src: ['**/*.css'],
dest: 'css/'
}]
}
},
watch: {
scripts: {
files: ['css-dev/*.css'],
tasks: ['postcss'],
options: {
spawn: false
}
}
}
});
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-watch');
};
如您所见,我想使用postcss-import Grunt 插件将bootstrap.css 文件导入css-dev/main.css 文件并缩小结果并将最终文件作为css 目录中的main.css 文件名。
css-dev 目录中main.css 文件的内容是:
@import "bootstrap.css";
/* normalize selectors */
h1::before, h1:before {
/* reduce shorthand even further */
margin: 10px 20px 10px 20px;
/* reduce color values */
color: #ff0000;
/* drop outdated vendor prefixes */
-webkit-border-radius: 16px;
border-radius: 16px;
/* remove duplicated properties */
font-weight: normal;
font-weight: normal;
/* reduce position values */
background-position: bottom right;
}
/* correct invalid placement */
@charset "utf-8";
.test{
font: 12px Calibri;
}
我认为一切都是正确的,但是在运行 grunt 任务之后,@import 似乎无法正常工作,结果文件是这样的:
@import "bootstrap.css";h1:before{margin:10px 20px;color:red;border-radius:16px;font-weight:400;background-position:100% 100%}.test{font:2px Calibri}
意味着意外地,引导文件的内容未导入到main.css 文件中。
什么问题,我该如何解决?
【问题讨论】:
标签: javascript css twitter-bootstrap gruntjs