Gruntfile で以下を使用しています。
grunt.initConfig({
assets: grunt.option('assets'),
config: grunt.file.readJSON(path.join('<%= assets %>', 'config.json')) || grunt.file.readJSON('./defaults.json'),
...
})
実行すると、次のようにスローされます。
>> Error: Unable to read "<%= assets %>/config.json" file (Error code: ENOENT).
>> at Object.util.error (/.../prj/node_modules/grunt-legacy-util/index.js:54:39)
>> at Object.file.read (/.../prj/node_modules/grunt/lib/grunt/file.js:247:22)
>> at Object.file.readJSON (/.../prj/node_modules/grunt/lib/grunt/file.js:253:18)
>> at Object.module.exports (/.../prj/Gruntfile.js:10:28)
>> at loadTask (/.../prj/node_modules/grunt/lib/grunt/task.js:325:10)
>> at Task.task.init (/.../prj/node_modules/grunt/lib/grunt/task.js:437:5)
>> at Object.grunt.tasks (/.../prj/node_modules/grunt/lib/grunt.js:120:8)
>> at Object.module.exports [as cli] (/.../prj/node_modules/grunt/lib/grunt/cli.js:38:9)
>> at Object.<anonymous> (/usr/local/lib/node_modules/grunt-cli/bin/grunt:45:20)
>> at Module._compile (module.js:425:26)
これは、assets
使用しようとしている時点で var が定義されていないためでしょうか? または、 <%= %> 構文はこの方法で使用できませんか?
この答えによると、うまくいくはずです-以前は を使っていたので見つけましたvar assets = grunt.option('assets')
が、それSyntaxError: Unexpected token var
は何らかの理由で投げていました。(いじる前はこんな感じでした:)
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt)
var util = require('util'),
path = require('path'),
pkg = require('./package.json')
var assets = grunt.option('assets'),
var config = grunt.file.readJSON(path.join(assets, 'config.json')) || grunt.file.readJSON('./defaults.json')
grunt.initConfig({
...
})
モジュールを使用したり、このように gruntfile 内で変数を宣言したりする適切でうなり声のある方法は何ですか? または、問題を解決できUnexpected token var
ますか?
(注:読み込みに問題があるのは構成ファイルではありません。アセットのパスgrunt.option()
が解釈されていないように見えるためです)