【问题标题】:Gulp + Browserify: CoffeeScript not loading when loading files from node_modulesGulp + Browserify:从 node_modules 加载文件时未加载 CoffeeScript
【发布时间】:2014-11-06 16:19:44
【问题描述】:

为我的 Gulp 项目设置文件夹结构后,我想知道如何在 browserify 中做路径,发现这个页面:https://github.com/substack/browserify-handbook#organizing-modules。它建议将常用应用程序部件放在node_modules 的子文件夹中。这似乎有效,它正在获取文件,但它没有应用我的coffeeify 转换,所以它会抛出错误,因为它试图将它们解释为 JS。任何想法如何解决这一问题?这是我的 browserify 配置:

browserify: {
  // Enable source maps
  debug: true,
  // Additional file extentions to make optional
  extensions: ['.coffee', '.hbs'],
  // A separate bundle will be generated for each
  // bundle config in the list below
  bundleConfigs: [{
    entries: src + '/javascript/app.coffee',
    dest: dest,
    outputName: 'app.js'
  }, {
    entries: src + '/javascript/head.coffee',
    dest: dest,
    outputName: 'head.js'
  }]
}

这些是我的package.json 中的相关位。

"browserify": {
  "transform": [
    "coffeeify",
    "hbsfy"
  ]
}

【问题讨论】:

标签: coffeescript gulp browserify


【解决方案1】:

Transfroms 不会应用于 node_modules 中的文件,除非它们被标记为全局:https://github.com/substack/node-browserify#btransformtr-opts。如果您选择使其全局化,请注意,文档建议不要这样做:

谨慎而谨慎地使用全局变换,因为大多数时候 一个普通的变换就足够了。

您将无法在package.json 中指定转换:

您也不能在 package.json 中配置全局转换,例如 你可以用普通的变换。

这两个选项以编程方式,通过将{global: true} 作为选项传递或在命令行使用-g 选项传递:

browserify -g coffeeify main.coffee > bundle.js

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 2021-07-03
    • 2018-07-10
    • 2013-03-25
    相关资源
    最近更新 更多