简体   繁体   English

早午餐如何禁用RequireJS模块包装

[英]Brunch how to disable RequireJS module wrapping

Update: For anyone interested in using Brunch with AngularJS I've put together a seed project angular-brunch-seed 更新:对于任何有兴趣使用早午餐AngularJS的人,我已经组建了一个种子项目角 - 早午餐种子

I'm using Brunch with AngularJS . 我正在使用BrunchAngularJS AngularJS provides a module system so the need for importing file using commonJS / AMD is redundant. AngularJS提供了一个模块系统,因此使用commonJS / AMD导入文件的需求是多余的。 Is it possible to disable this feature for files in the /app directory? 是否可以为/app目录中的文件禁用此功能? Essentially I would like it to compile files unaltered like it does for the /vendor directory. 基本上我希望它像/vendor目录一样编译文件。

So the preferred out come would be: 所以首选的是:

  joinTo:
    'js/app.js': /^app/
    'js/vendor.js': /^vendor/

With both js/app.js and js/vender.js containing compile files from each respective folder, but neither wrapped. 同时js/app.jsjs/vender.js包含来自每个相应文件夹的编译文件,但都没有包装。

Does anyone have any ideas? 有没有人有任何想法?

UPDATE The syntax has changed from when @jcruz answer. 更新语法已从@jcruz回答时更改。 Here's the way to do this now. 现在就是这样做的方法。

In the end I went with a modified version of @jcruz answer. 最后,我使用了@jcruz答案的修改版本。

exports.config =
  modules:
    definition: false
    wrapper: (path, data) ->
      """
(function() {
  'use strict';
  #{data}
}).call(this);\n\n
      """
  files:
    javascripts:
      defaultExtension: 'coffee'
      joinTo:
        'js/app.js': /^app/
        'js/vendor.js': /^vendor/

By default the "raw" wrapper does not include coffeescript's standard wrapper. 默认情况下,“原始”包装器不包含coffeescript的标准包装器。 By setting jsWrapper to: 通过将jsWrapper设置为:

wrapper: (path, data) ->
  """
(function() {
  'use strict';
  #{data}
}).call(this);
  """

files will be wrapped as expected. 文件将按预期包装。

This has changed to a module configuration now, as far as I can see: https://github.com/brunch/brunch/blob/stable/docs/config.md#modules 现在,就我所见,这已改为模块配置: https//github.com/brunch/brunch/blob/stable/docs/config.md#modules

exports.config =
  paths:
    ...
  files:
    ...
  modules:
    wrapper: false
    definition: false

The ability to disable the module wrapping was just recently added in https://github.com/brunch/brunch/commit/ec158cffd1b66d5db2093cf766000673aa0dd3a5 最近在https://github.com/brunch/brunch/commit/ec158cffd1b66d5db2093cf766000673aa0dd3a5中添加了禁用模块包装的功能

I dont believe the release w/ these features is on npm yet but you could just re-install brunch from the github repo 我不相信这些功能的发布还在npm上,但你可以从github repo重新安装早午餐

Once you do that Brunch, set jsWrapper to 'raw' in your config.coffee 完成早午餐后,在config.coffee中将jsWrapper设置为'raw'

Something like this... 像这样......

exports.config =
  jsWrapper: 'raw'
  files:
    javascripts:
      defaultExtension: 'js'
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/

'brunch b' and the wrapping code should disappear '早午餐b'和包装代码应该消失

As of (almost) 2017 Jan, it is imperative to declare npm enabled to false along with module settings. 从(差不多)2017年1月开始,必须将npm声明与模块设置一起声明为false。 It took me a while to find out, though. 不过,我花了一段时间才发现。 (Found this via a GitHub issue ). (通过GitHub问题找到了这个)。 Hope this helps. 希望这可以帮助。 Cheers. 干杯。

Here is a working config file: 这是一个有效的配置文件:

// See http://brunch.io for documentation.
module.exports = {
    files: {
      javascripts: {
        joinTo: {
          '/js/app.js': /^app/,
          '/js/vendor.js': /^(?!app)/
        }
      },
      stylesheets: {
        joinTo: 'css/app.css'
      }
    },

    paths: {
      public: '/priv/static'
    },

    npm: {
      enabled: false
    },

    modules: {
      wrapper: false,
      definition: false
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM