2016-05-02 1 views
2

私の下線アンダースコアプロジェクトを構成するためのベストプラクティスを理解しようとしています。SASS - ページテンプレートの別のスタイルシートを出力する

私はnpmとgruntを使って基本的な作業環境を持っていて、メインのCSSをコンパイルしますが、サブフォルダに複数のページテンプレートを作成し、それぞれの.scssファイルを/ layoutフォルダに出力します// //

.gitignore 
404.php 
archive.php 
comments.php 
/compiled 
    style-human.css // Readable CSS Before prefixing // 
    style.css // Minified CSS Before Prefixing // 
    /page-layouts 
     page-frontage.human.css // Readable page-template CSS before prefixing // 
     page-frontage.css // minified page-template CSS before prefixing // 
/fonts 
footer.php 
functions.php 
gruntfile.js 
header.php 
/inc 
index.php 
/js 
/languages 
/node_modules 
package.json 
/page-layouts 
    page-frontage.css // prefixed minified CSS to be Enqueued after main style.css in functions.php // 
    page-frontage-human.css // prefixed readable CSS // 
/page-templates 
    page-frontpage.php 

page.php 
rtl.css 
/sass 
    _normalize.scss 
    /elements 
    /forms 
    /layout 
     _footer 
     _header 
     /page-layouts 
      _page-frontpage.scss 
    /media 
    /mixins 
    /modules 
    /navigation 
    /site 
    style.css // @imports everything SCSS except page-layouts // 
    /variables-site 
search.php 
sidebar.php 
single.php 
style-human.css // readable main stylesheet // 
style.css // minified main stylesheet Enqueued in functions.php // 
/template-parts  

を更新これはコードです:私は大体この順番で私のプロジェクトファイルを構造化function.php

でメインのスタイルシートの後の.cssとして独立したページテンプレートのスタイルシートをエンキューできること私は私のgruntfile.jsで使用した

module.exports = function(grunt){ 

    grunt.initConfig({ 

     pkg: grunt.file.readJSON('package.json'), 

     /** 
     * sass task 
     */ 
     sass: { 
      dev: { 
       options: { 
        style: 'expanded', 
        sourcemap: 'none', 
       }, 
       files: { 
       'compiled/style-human.css': 'sass/style.scss' 
       } 
     }, 
     dist: { 
       options: { 
        style: 'compressed', 
        sourcemap: 'none', 
       }, 
       files: { 
       'compiled/style.css': 'sass/style.scss' 
       } 
      } 
     }, 

     /** 
     * Autoprefixer 
     */ 
     autoprefixer: { 
      options: { 
      browsers: ['last 2 versions'] 
      }, 
      // prefix all files // 
      multiple_files: { 
      expand: true, 
       flatten: true, 
       src: 'compiled/*.css', 
       dest: '' 
      } 
     }, 

     /** 
     * Watch task 
     */ 
     watch: { 
      css: { 
       files: '**/*scss', 
       tasks: ['sass','autoprefixer']  
     } 
    } 

    }); 
    grunt.loadNpmTasks ('grunt-contrib-sass'); 
    grunt.loadNpmTasks ('grunt-contrib-watch'); 
    grunt.loadNpmTasks ('grunt-autoprefixer'); 
    grunt.registerTask('default',['watch']); 
} 

今私はいくつかの解決策を試しましたが、私はgruntfile.jsをどのように構造化してレイアウトファイルに2つのページテンプレートscssを自動プレフィックスcssとして出力するのか理解できません。

+0

Doeさんの実際のコードは何ですか? – sab

+0

今、私のstyle.scssが人間の読めるスタイルhuman.cssとコンパイルされたstyle.cssにコンパイルされ、コンパイルされたフォルダに置かれ、それらのファイルに対してautoprefixerが実行され、ルートに置かれます私のテーマファイルの –

+0

私は基本的にそれをやり続けたいと思うし、また私の/ page-templateのscssファイルを取って手続きをやり直してそれらのファイルの接頭辞を付けて、最終的にそれらを/ページテンプレートフォルダに入れて、 functions.phpのmain main style.css –

答えて

0

私の見ているところでは、デフォルトタスクはscssファイルが更新された場合にのみ、sassとautoprefixerタスクを起動するウォッチタスクを起動します。

あなたは使用する必要があります:それはスレッドを停止するので

grunt.registerTask('default',['sass','autoprefixer']); 

実際には、我々は、デフォルトのタスクに時計のタスクを置かないでください。いったんサーバーを起動すると、監視タスクが呼び出されます。私は可能な解決策、おそらく最もエレガントなものを見つけることができたが、それは動作しますが、並べ替えの...

の(あなたのgruntfileの同じレベルの端末にコマンドgrunt watchを使用)

+0

私はあなたに従っていると確信していますか?私はgruntfile.jsを実際に使いこなし始めたときに今日まで立ち上がっていたので、腕時計タスクを実行し、.scssアップデートを見たいと思っています。いつでも私は何かを変更しました。 scssファイルでは、2つのスタイルシート、style-human.cssおよびstyle.cssを更新して自動プレフィクスしました。 あなたの提案との正確な違いは何ですか? –

1

ソート私のファイルは、このような構造:

.gitignore 
404.php 
archive.php 
comments.php 
/compiled 
    style-human.css //-- Readable CSS Before prefixing --// 
    style.css //-- Minified CSS Before Prefixing --// 
    /page-layouts 
     frontage.human.css //-- Readable page-template CSS before prefixing --// 
     frontage.css //-- minified page-template CSS before prefixing --// 
/fonts 
footer.php 
functions.php 
gruntfile.js 
header.php 
/inc 
index.php 
/js 
/languages 
/node_modules 
package.json 
/page-layouts 
    frontage.css //-- prefixed minified CSS to be Enqueued after main style.css in functions.php --// 
    frontage-human.css //-- prefixed readable CSS --// 
/page-templates 
    frontage.php //-- code for template goes here, Enqueued in functions.php --// 
page.php 
rtl.css 
/sass 
    _normalize.scss 
    /elements 
    /forms 
    /layout 
     _footer 
     _header 
     /page-layouts //-- working folder for all page templates --// 
      _frontpage.scss //-- SASS for page template goes here! --// 
    /media 
    /mixins 
    /modules 
    /navigation 
    /page-templates 
     frontpage.scss //-- @imports content of ../layout/page-layouts/_frontpage.scss --// 
    /site 
    style.css //-- @imports everything SCSS except /page-layouts --// 
    /variables-site 
search.php 
sidebar.php 
single.php 
style-human.css //-- readable main stylesheet --// 
style.css //-- minified main stylesheet Enqueued in functions.php --// 
/template-parts  

そして

module.exports = function(grunt){ 

    grunt.initConfig({ 

     pkg: grunt.file.readJSON('package.json'), 

     /** 
     * sass task 
     */ 
     sass: {    // Task 
      dev: {    // Target 
       options: {  // Target options 
        style: 'expanded', 
        sourcemap: 'none', 
       }, 
       files: {  // Dictionary of files 
       'compiled/style-human.css': 'sass/style.scss', // 'destination': 'source' 
        'compiled/page-layouts/frontpage-human.css': 'sass/page-templates/frontpage.scss' // 'destination': 'source' 
       } 
     }, 
     dist: {    // Target 
       options: { // Target options 
        style: 'compressed', 
        sourcemap: 'none', 
       }, 
       files: {  // Dictionary of files 
       'compiled/style.css': 'sass/style.scss', // 'destination': 'source' 
        'compiled/page-layouts/frontpage.css': 'sass/page-templates/frontpage.scss' // 'destination': 'source' 

       } 
      } 
     }, // close sass task 

     /** 
     * Autoprefixer 
     */ 
     autoprefixer: { 
      options: { 
      browsers: ['last 2 versions'] 
      }, 
      // prefix all files // 
      multiple_files: { 
      expand: true, 
       flatten: true, 
       src: 'compiled/*.css', 
       dest: '' 
      }, 
      // prefix frontpage template // 
      multiple_files: { 
      expand: true, 
       flatten: true, 
       src: 'compiled/page-layouts/*.css', 
       dest: './page-layouts' 
      }, 
     }, 

     /** 
     * Watch task 
     */ 
     watch: { 
      css: { 
       files: '**/*scss', 
       tasks: ['sass','autoprefixer']  
     } 
    } 

    }); 
    grunt.loadNpmTasks ('grunt-contrib-sass'); 
    grunt.loadNpmTasks ('grunt-contrib-watch'); 
    grunt.loadNpmTasks ('grunt-autoprefixer'); 
    grunt.registerTask('default',['watch']); 
} 

基本的にこれは私がPA、それを意図したどのように作品を以下のように私は私のGruntfile.jsを構造化ge-templateスタイルシートは、意図したpage-layoutsフォルダに人間が読める/縮小された自動プレフィックスバージョンとして保存されるので、function.phpのmain.cssの後にエンキューできます。

"私のページテンプレートのscssファイルは変数を理解していません...

+0

意図したとおりに動作するようにしました。問題は、私のfrontage.scssファイルで間違った順序でファイルをインポートしたことです。もちろん、変数とミックスインを使ってページテンプレートファイルをインポートする前に、まず変数-site.scssとmixing-site.scssをインポートする必要があります。 .. –

関連する問題