質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

gulp

gulpは、Node.jsをベースとしたタスク自動化ツールの一つ。ストリームでファイルを処理することが特徴です。CSSプリプロセッサの使用時のコンパイルや、CSS・JavaScriptファイルの圧縮・結合などを自動的に行うことができます。

Q&A

1回答

2676閲覧

postcss-custom-propertiesがうまく動きません。

退会済みユーザー

退会済みユーザー

総合スコア0

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

gulp

gulpは、Node.jsをベースとしたタスク自動化ツールの一つ。ストリームでファイルを処理することが特徴です。CSSプリプロセッサの使用時のコンパイルや、CSS・JavaScriptファイルの圧縮・結合などを自動的に行うことができます。

0グッド

0クリップ

投稿2016/07/12 09:07

postcss-custom-propertiesがうまく動きません。

・エラー
throw new gutil.PluginError('gulp-postcss', 'Please provide array of postcss processors!')
^
Error: Please provide array of postcss processors!

・gulpfile.js

//gulpfile.js var gulp = require('gulp'); //gulpをインポート var postcssimport = require('postcss-import'); var postcss = require('gulp-postcss'); //gulp-postcssをインポート var cssnext = require('postcss-cssnext'); //cssnextをインポート var nested = require('postcss-nested'); var reporter = require('postcss-reporter'); //stylelintだけだとレポートが出力されない為 var csswring = require('csswring'); var calc = require('postcss-calc'); var customProperties = require("postcss-custom-properties"); var customMedia = require("postcss-custom-media"); //うまくいっていない。カスタムメディアクエリーズが使える var plumber = require('gulp-plumber');//うまくいっていない。gulpのwatchが止まらないようにする gulp.task('css', function () { //”css”タスクを登録 var plugins = [ postcssimport, cssnext, //一旦空の配列を作成 nested, reporter, calc, csswring, customProperties, customMedia, plumber ]; return gulp.src( ['./src-before/*' , './src-before/*/*'], { base: 'src-before' }) //src-before下にある.cssファイルを指定 .pipe(postcss(plugins)) //PostCSSにファイルを処理してもらう .pipe(gulp.dest('./dest-after/css')); //生成されたCSSをdest-after下に配置 }); //以下gulp-watch gulp.task('watch', function(){ gulp.watch(['./src-before/*' , './src-before/*/*' , './src-before/*/*/*'], ['css']);//監視したいファイルの相対パス });

・gulpは難しくて、英語の公式サイトを見てもよくわかりません。

varと
var pluginsの中とこの二つを記載するだけで動くものが多いですが、
そうでないものは一体どうやったら使えるのでしょうか?

日本語の情報がありません

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

pluginsがArrayになっていないようです。
pluginsの定義の後で、 !Array.isArray(plugins)の値がどうなってるかをログを取って見てみてください。

https://github.com/postcss/gulp-postcss/blob/master/index.js#L10

投稿2016/07/13 09:20

k.tada

総合スコア1679

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2016/07/13 09:41

下記のようにしましたが、うまくいきません。 >>> //gulpfile.js var gulp = require('gulp'); //gulpをインポート var postcssimport = require('postcss-import'); var postcss = require('gulp-postcss'); //gulp-postcssをインポート var cssnext = require('postcss-cssnext'); //cssnextをインポート var nested = require('postcss-nested'); var reporter = require('postcss-reporter'); //stylelintだけだとレポートが出力されない為 var csswring = require('csswring'); var calc = require('postcss-calc'); var customProperties = require("postcss-custom-properties"); var customMedia = require("postcss-custom-media"); //うまくいっていない。カスタムメディアクエリーズが使える var plumber = require('gulp-plumber');//うまくいっていない。gulpのwatchが止まらないようにする var Stream = require('stream') var postcss = require('postcss') var applySourceMap = require('vinyl-sourcemaps-apply') var gutil = require('gulp-util') module.exports = function (processors, options) { if (!Array.isArray(processors)) { throw new gutil.PluginError('gulp-postcss', 'Please provide array of postcss processors!') } var stream = new Stream.Transform({ objectMode: true }) stream._transform = function (file, encoding, cb) { if (file.isNull()) { return cb(null, file) } if (file.isStream()) { return handleError('Streams are not supported!') } // Source map is disabled by default var opts = { map: false } var attr // Extend default options if (options) { for (attr in options) { if (options.hasOwnProperty(attr)) { opts[attr] = options[attr] } } } opts.from = file.path opts.to = opts.to || file.path // Generate separate source map for gulp-sourcemap if (file.sourceMap) { opts.map = { annotation: false } } postcss(processors) .process(file.contents, opts) .then(handleResult, handleError) function handleResult (result) { var map var warnings = result.warnings().join('\n') file.contents = new Buffer(result.css) // Apply source map to the chain if (file.sourceMap) { map = result.map.toJSON() map.file = file.relative map.sources = [].map.call(map.sources, function (source) { return path.join(path.dirname(file.relative), source) }) applySourceMap(file, map) } if (warnings) { gutil.log('gulp-postcss:', file.relative + '\n' + warnings) } setImmediate(function () { cb(null, file) }) } function handleError (error) { var errorOptions = { fileName: file.path, showStack: true } if (error.name === 'CssSyntaxError') { error = error.message + error.showSourceCode() errorOptions.showStack = false } // Prevent stream’s unhandled exception from // being suppressed by Promise setImmediate(function () { cb(new gutil.PluginError('gulp-postcss', error, errorOptions)) }) } } gulp.task('css', function () { //”css”タスクを登録 var plugins = [ postcssimport, cssnext, //一旦空の配列を作成 nested, reporter, calc, csswring, customProperties, customMedia, plumber ]; return gulp.src( ['./src-before/*' , './src-before/*/*'], { base: 'src-before' }) //src-before下にある.cssファイルを指定 .pipe(postcss(plugins)) //PostCSSにファイルを処理してもらう .pipe(gulp.dest('./dest-after/css')); //生成されたCSSをdest-after下に配置 }); //以下gulp-watch gulp.task('watch', function(){ gulp.watch(['./src-before/*' , './src-before/*/*' , './src-before/*/*/*'], ['css']);//監視したいファイルの相対パス }); ・エラー SyntaxError: Unexpected token ) at Object.exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:513:28) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Liftoff.handleArguments (C:\Users\hoto\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:116:3) at Liftoff.<anonymous> (C:\Users\hoto\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\index.js:193:16) ;がないからでしょうか?
k.tada

2016/07/13 09:47 編集

ん??ごめんなさい、単純に`css`のgulpタスクにログ仕込んでもらって、その値を確認してほしかっただけなのですが・・・汗 ``` gulp.task('css', function () { //”css”タスクを登録 var plugins = [ 略 ]; console.log( Array.isArray(plugins) ); // ★ココを追加 return gulp.src( ['./src-before/*' , './src-before/*/*'], { base: 'src-before' }) //src-before下にある.cssファイルを指定 .pipe(postcss(plugins)) //PostCSSにファイルを処理してもらう .pipe(gulp.dest('./dest-after/css')); //生成されたCSSをdest-after下に配置 }); ```
退会済みユーザー

退会済みユーザー

2016/07/13 10:17

了解しました、下記のように出ました。 >>> (node:8964) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version. [19:16:04] Using gulpfile ~\Desktop\images\gulp-folder\postcss\gulpfile.js [19:16:04] Starting 'css'... true src-before/app.css 15:1 ‼ Failed to find 'layout/__drawer-menu' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] [postcss-import] 25:1 ‼ Failed to find 'object/component/_gnavi' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] [postcss-import] 27:1 ‼ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\object\component\_card.css:31:2: Unknown word [postcss-import] 34:1 ‼ Failed to find 'object/component/_logo' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] [postcss-import] 35:1 ‼ Failed to find 'object/component/_catch' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] [postcss-import] 36:1 ‼ Failed to find 'object/component/_news' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] [postcss-import] src-before/object/utility/_utility-style.css 157:2 ‼ You should write display: flex by final spec instead of display: box [autoprefixer] [19:16:05] gulp-postcss: app.css postcss-import: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\app.css:27:1: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\object\component\_card.css:31:2: Unknown word postcss-import: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\app.css:15:1: Failed to find 'layout/__drawer-menu' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] postcss-import: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\app.css:34:1: Failed to find 'object/component/_logo' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] postcss-import: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\app.css:25:1: Failed to find 'object/component/_gnavi' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] postcss-import: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\app.css:35:1: Failed to find 'object/component/_catch' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] postcss-import: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\app.css:36:1: Failed to find 'object/component/_news' in [ C:\Users\user\Desktop\images\gulp-folder\postcss\src-before ] autoprefixer: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\object\utility\_utility-style.css:157:2: You should write display: flex by final spec instead of display: box src-before/style.css 15:1 ‼ variable '--color-primary' is undefined and used without a fallback [postcss-custom-properties] [19:16:05] gulp-postcss: style.css postcss-custom-properties: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\style.css:15:1: variable '--color-primary' is undefined and used without a fallback postcss-custom-properties: C:\Users\user\Desktop\images\gulp-folder\postcss\src-before\style.css:15:1: variable '--color-primary' is undefined and used without a fallback [19:16:06] Finished 'css' after 2.35 s
k.tada

2016/07/13 11:06

うーん、pluginsはArrayになっていますが、そもそもいろいろとエラーが出ているんですね。。。 ※ 上からざっと見ていくと、まずpostcss-importでモジュールが見つからないエラーが出ているようです。 この辺のバグを一つ一つ直していくしか無いと思います。。
退会済みユーザー

退会済みユーザー

2016/07/14 01:48

確かに、まだ作っていないファイルがあるので、そのように出ますがそれが原因ということはあり得るのですか? ミニファイなどは問題なくできています。 それが原因ならすべてできないというものではないのですか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問