0

WordPressサイトでMAMPでgrunt-uncssを使用しています。すべての css ファイルを取得し、それらを 1 つのファイルに結合しました。

結果: 1 つの URL が完了するまでに 40 分かかります。それは効率的ではありません。さらに、uncss は、開始時と同じ css を吐き出すだけです。

エラーの多くは「ReferenceError: 変数が見つかりません: jQuery」ですが、PhantomJS/UnCSS がインライン JavaScript を解析しようとしているようなものですか?

ここにいくつかの他のものがあります:

SyntaxError:予期しないトークン '%'

local:193 in setContent:2 SyntaxError: 識別子の無効なエスケープ: '\'

local:427 in setContent:2 SyntaxError: 予期しないトークン '<'

local:891 in setContent:2 SyntaxError: 予期しないトークン ','

jQueryの読み込み時間(タイムアウト)の追加など、さまざまなアプローチを試しました。また、過去7時間のグーグル検索も試しました。問題は PhantomJS にあると確信していますが、それに慣れていません。助けを求めている

これが私のグラントファイルです

module.exports = function(grunt) {

   require('time-grunt')(grunt);

  // 1. All configuration goes here 
     grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

      jshint: {
        all: ['gruntfile.js']
      },

  exec: {
      get_grunt_sitemap: {
         command: 'curl --silent --output sitemap.json http://localhost:8888/applus/?show_sitemap'
      }
    },

  uncss: {
     dist: {
        options: {
      ignore       : [
                /expanded/,
                /js/,
                /wp-/,
                /align/,
                /admin-bar/,
                /\w\.in/,
                ".fade",
                ".collapse",
                ".collapsing",
                /(#|\.)navbar(\-[a-zA-Z]+)?/,
                /(#|\.)dropdown(\-[a-zA-Z]+)?/,
                /(#|\.)(open)/,
                ".modal",
                ".modal.fade.in",
                ".modal-dialog",
                ".modal-document",
                ".modal-scrollbar-measure",
                ".modal-backdrop.fade",
                ".modal-backdrop.in",
                ".modal.fade.modal-dialog",
                ".modal.in.modal-dialog",
                ".modal-open",
                ".in",
                ".modal-backdrop",
                '.hidden-xs', 
                'hidden-sm'

                ],
      stylesheets  : ['wp-content/themes/vest/css/consolidated.css'],
      ignoreSheets : [/fonts.googleapis/],
      urls         : [], //Overwritten in load_sitemap_and_uncss task
    },
    files: {
      'wp-content/themes/vest/style.test.css': ['**/*.php']
    }
  }
}

  });

// 3. Where we tell Grunt we plan to use this plug-in.
      grunt.loadNpmTasks('grunt-contrib-jshint');
      grunt.loadNpmTasks('grunt-exec');   
      grunt.loadNpmTasks('grunt-uncss');

// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
      grunt.registerTask('load_sitemap_json', function() {
      var sitemap_urls = grunt.file.readJSON('./sitemap.json');
      grunt.config.set('uncss.dist.options.urls', sitemap_urls);
 });

  grunt.registerTask('deploy'['jshint','exec:get_grunt_sitemap','load_sitemap_json','uncss:dist']);  
 };
4

1 に答える 1

0

わかりました、それで私自身の質問に答えます。MAMP のスタイルシートとファイルの URL を誤って設定したようです。ファイルへのハードリンクを作成したらすぐに。ユーザーの操作によってトリガーされるイベントを除いて、すべてが機能しているように見えました。

ここに私が行った変更があります:

stylesheets  : ['http://localhost:8888/wp-content/themes/vest/css/consolidated.css'],



files: [{
                nonull: true,
                src: ['http://localhost:8888/applus'],
                dest: '/Applications/MAMP/htdocs/applus/wp-content/themes/cannavest/uncss-style.css'
    }]

ヒント: WordPress の場合、ページ ソースを確認し、ページ ソースに表示される特定の順序ですべての css を 1 つの css ファイルにコピーする必要があります (つまり、consolidated.css)。そうすれば、完成したサイトと同じくらい多くの CSS 継承を維持できます。

于 2016-11-28T18:28:04.623 に答える