2016-04-08 17 views
0

postcssモジュールをローカルにインストールするには、どうすればpostcss-cliがグローバルにインストールされますか?例えばpostcss-cli:グローバルにインストールされたpostcssモジュールを使用する

postcss -u autoprefixer -o style.css index.css 

このコマンドの作品は、私が持っている場合postcss-cliautoprefixerはグローバルにインストール、またはその両方がローカルにインストールされている場合。しかし、私はpostcss-cliがグローバルにインストールされていて、ローカルにautoprefixerがあると動作しません。

この問題は、autoprefixerに固有の問題ではありません。なぜなら、autoprefixerはモジュールであり、私はどのようにグローバルにインストールしたのでしょうか。どんな助言も役に立つでしょう。

postcss-cliがグローバルにインストールされ、ローカルでautoprefixerされる場合、これは、私が取得エラーです:

> postcss -u autoprefixer -o style.css index.css -w 

module.js:327 
    throw err; 
    ^

Error: Cannot find module 'autoprefixer' 
    at Function.Module._resolveFilename (module.js:325:15) 
    at Function.Module._load (module.js:276:25) 
    at Module.require (module.js:353:17) 
    at require (internal/module.js:12:17) 
    at /home/user/.nvm/versions/node/v4.4.2/lib/node_modules/postcss-cli/index.js:104:14 
    at Array.map (native) 
    at Object.<anonymous> (/home/user/.nvm/versions/node/v4.4.2/lib/node_modules/postcss-cli/index.js:97:24) 
    at Module._compile (module.js:409:26) 
    at Object.Module._extensions..js (module.js:416:10) 
    at Module.load (module.js:343:32) 

npm ERR! Linux 3.19.0-58-generic 
npm ERR! argv "/home/user/.nvm/versions/node/v4.4.2/bin/node" "/home/user/.nvm/versions/node/v4.4.2/bin/npm" "run" "css" 
npm ERR! node v4.4.2 
npm ERR! npm v2.15.0 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] css: `postcss -u autoprefixer -o style.css index.css -w` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] css script 'postcss -u autoprefixer -o style.css index.css -w'. 
npm ERR! This is most likely a problem with the Node.js package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  postcss -u autoprefixer -o style.css index.css -w 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs Node.js 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR! 
npm ERR!  npm owner ls Node.js 
npm ERR! There is likely additional logging output above. 
+0

私はローカルにすべてをインストールします。それはあなたを悩ませますか? – topheman

+0

@tophemanプロジェクトごとに1つの場所に1度に1つのCLIをインストールすると便利です。 –

+0

もし私が同じバグを抱えていたら、すべてのものをローカルにインストールし、 './node_modules/.bin/postcss -u autoprefixer -o style.css index.css'のようなnpmスクリプトを作成してください。 **プロジェクトに上陸する際に**グローバル依存関係は必要ありません)。しかし、CLIを一度だけインストールしたいと思うことも理解できます。これは 'postcss-cli'リポジトリに提出するべきバグのようです。 – topheman

答えて

1

あなたがそうのような設定ファイルを作成することができますpostcss-CLIを使用している場合:

{ 
    "use": [ 
     "postcss-import", 
     "postcss-cssnext", 
     "lost", 
     "rucksack-css", 
     "postcss-autoreset", 
     "postcss-font-magician" 
    ], 
    "input": "src/app.css", 
    "output": "css/main.css", 
    "local-plugins": true, 
    "autoprefixer": { 
     "browsers": "last 2 versions" 
    } 
} 

"local-plugins": true,行に注目してください。ドキュメントから:

現在の作業ディレクトリにあるnode_modulesから始まるプラグインを検索します。このオプションを指定しないと、postcss-cliはインストールされているnode_modules内のプラグインを探します。特に、グローバルにインストールされている場合は、グローバルにインストールされているプラ​​グインのみが検索されます。

設定ファイルを使用しない場合は、オプション--local-pluginsを使用できます。

常にローカルにインストールすることをお勧めします。あなたはいつもそれが簡単にそうようなpostcss-cliを実行できるようにすることpackage.jsonにNPMスクリプトを作成することができます

"scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "build": "node_modules/postcss-cli/bin/postcss -c config.json", 
    "watch": "node_modules/postcss-cli/bin/postcss -c config.json -w", 
    "minify": "node_modules/postcss-cli/bin/postcss -c config-minify.json" 
}, 

今、あなたは、単に使用します。

npm run build 
関連する問題