Struktur meines Projekts ist wie folgt funktioniert:postcss-Import Grunzen-Plugin nicht
my_project
|-- css
| -- main.css
|-- css-dev
| -- main.css
|-- node_modules
| -- bootstrap
| -- dist
| -- css
| -- bootstrap.css
|-- package.json
`-- Gruntfile.js
Und mein Gruntfile.js
ist wie folgt:
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');
};
Wie Sie sehen, ich postcss-import Grunt verwenden möchten Plugin zum bootstrap.css
Datei in css-dev/main.css
Datei zu importieren und Ergebnis zu minimieren und endgültige Datei in css
Verzeichnis als main.css
Dateiname.
Inhalt von main.css
Datei in css-dev
Verzeichnis ist:
@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;
}
Ich denke, dass alles korrekt sind, aber nach Grunzen Aufgaben ausgeführt wird, scheint @import
nicht richtig und Ergebnisdatei ist wie folgt funktioniert:
@import "bootstrap.css";h1:before{margin:10px 20px;color:red;border-radius:16px;font-weight:400;background-position:100% 100%}.test{font:2px Calibri}
Means Unerwarteter Inhalt der Bootstrap-Datei nicht in main.css
Datei importiert.
Was ist das Problem, wie kann ich das lösen?
Ihre Lösung funktioniert, aber Ihr Weg ist nur fo r Bootstrap aber was ist, wenn ich andere CSS-Bibliotheken importieren möchte? –
entsprechend Ihrer Anleitung, ich Benutzer '@ import" bootstrap/dist/css/bootstrap.css ";' Bootstrap-Datei automatisch aus 'node_modules' Verzeichnis abzurufen. –
Das funktioniert auch, aber das ist genauso wie das Hinzufügen des Pfades zum postcss-import. Der Vorteil des Pfades in Ihrer Konfiguration bedeutet, dass wenn Sie diese CSS-Komponente in einem anderen Projekt wiederverwenden, Ihre CSS nicht an Ihre Projektstruktur gebunden ist, ist die Konfiguration. –