SailsJS链接器(Grunt)忽略文件(Gruntfile.js)

时间:2014-01-31 00:03:42

标签: node.js gruntjs sails.js

我正在使用凉亭进行资产管理。 Bootstrap bower repo随附了一个Gruntfile.js。

有没有办法从链接器中排除它?

我试过了:

var jsFilesToInject = [
     '!**Gruntfile.js',
//     ...
]

但它不起作用 - 我把这个字符串放在了错误的位置吗?

生成的HTML和错误

enter image description here

文件结构

enter image description here

P.S。我按照本指南前往:StackOverFlow Question并运行bower install bootstrapbower install angular

2 个答案:

答案 0 :(得分:5)

我的工作配置如下:

  • bower_components文件夹直接放在assets文件夹中。
  • 将所有与应用相关的文件放入linker文件夹

    | .bowerrc
    | assets/
    |-- bower_components/
    |---- bootstrap/
    |------ dist/
    |-------- bootstrap.js
    |---- angular/
    |-- linker/
    |---- js/
    |------ sails.io.js
    |------ socket.io.js
    |---- styles/
    |---- templates/
    

Gruntfile.js设置jsFileToInject设置

    var jsFilesToInject = [
        // Below, as a demonstration, you'll see the built-in dependencies
        // linked in the proper order order
        // Bring in the socket.io client
        'linker/js/socket.io.js',

        // then beef it up with some convenience logic for talking to Sails.js
        'linker/js/sails.io.js',

        // jQuery and plugins
        'bower_components/jquery/jquery.js',

        // Bootstrap
        'bower_components/bootstrap/dist/bootstrap.js',

        // Angular
        'bower_components/angular/angular.js',

        // App file that needs to load first
        'linker/js/app.js',

        // All of the rest of your app scripts imported here
        'linker/**/*.js'
    ];

在项目根目录的.bowerrc中,您输入了

    {
        "directory": "assets/bower_components"
    }

答案 1 :(得分:4)

这是当前风帆前端生成器中的一个错误。我有submitted a PR,但现有的应用程序必须手动修复,因为生成器只执行一次。

问题出现在当前Django Version: 1.8.4 Python Version: 2.7.6 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'plant', 'journal', 'userimg', 'django.contrib.sites', 'allauth', 'allauth.account') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware') Traceback: File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/core/handlers/base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/django/django_project/plant/views.py" in plant_main 24. return render(request, 'plant/plant_main.html', context) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/shortcuts.py" in render 67. template_name, context, request=request, using=using) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/loader.py" in render_to_string 99. return template.render(context, request) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/backends/django.py" in render 74. return self.template.render(context) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/base.py" in render 208. with context.bind_template(self): File "/usr/lib/python2.7/contextlib.py" in __enter__ 17. return self.gen.next() File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/context.py" in bind_template 237. processors = (template.engine.template_context_processors + File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/utils/functional.py" in __get__ 60. res = instance.__dict__[self.name] = self.func(instance) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/engine.py" in template_context_processors 90. return tuple(import_string(path) for path in context_processors) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/engine.py" in <genexpr> 90. return tuple(import_string(path) for path in context_processors) File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/utils/module_loading.py" in import_string 26. module = import_module(module_path) File "/usr/lib/python2.7/importlib/__init__.py" in import_module 37. __import__(name) Exception Type: ImportError at /plant/ Exception Value: No module named context_processors 文件的末尾,在实际导出设置的部分中。目前它是这样的:

pipeline.js

正如您所看到的,它会预先设置// pipeline.js //... Defined rules ... module.exports.cssFilesToInject = cssFilesToInject.map(function(path) { return '.tmp/public/' + path; }); module.exports.jsFilesToInject = jsFilesToInject.map(function(path) { return '.tmp/public/' + path; }); module.exports.templateFilesToInject = templateFilesToInject.map(function(path) { return 'assets/' + path; }); 文件夹或模板的tmp文件夹的相对路径。这导致了规则 <{1}}中的assets,可能与任何内容都不匹配。

解决方案是使用以下内容替换!js/foo.js中的上述块:

.tmp/public/!js/foo.js

这将检查给定规则是否以pipeline.js开头并正确添加,因此module.exports.cssFilesToInject = cssFilesToInject.map(function(path) { var tmpPath = '.tmp/public/'; if (path.substring(0,1) == '!') return '!' + tmpPath + path.substring(1); return tmpPath + path; }); module.exports.jsFilesToInject = jsFilesToInject.map(function(path) { var tmpPath = '.tmp/public/'; if (path.substring(0,1) == '!') return '!' + tmpPath + path.substring(1); return tmpPath + path; }); module.exports.templateFilesToInject = templateFilesToInject.map(function(path) { var tmpPath = 'assets/'; if (path.substring(0,1) == '!') return '!' + tmpPath + path.substring(1); return tmpPath + path; }); 将导致!正确匹配。

必须在创建结果集后设置排除项。这符合grunt's documentation。因此,对于您的情况,它将是:

!js/foo.js