简体   繁体   English

如何在package.json中指定browserify扩展?

[英]How to specify browserify extensions in package.json?

In package.json: 在package.json中:

...
"browserify": {
  "transform": [
    "coffee-reactify"
  ],
  "extension": [ ".cjsx", ".coffee", ".js", ".json" ],
  "extensions": [ ".cjsx", ".coffee", ".js", ".json" ]
},
...

When using browserify transform option works as expected, however browserify is not seeing extension(s) options - it throws error and I have to pass extension options manually to browserify... 当使用browserify transform选项按预期工作时,但是browserify没有看到extension(s)选项 - 它会抛出错误,我必须手动传递扩展选项以进行浏览...


in gulpfile.coffee 在gulpfile.coffee中

b = browserify
  entries: './' # ./ = root = directory where package.json is
  debug: true
b.bundle()
.pipe(source('client.js'))
.pipe(buffer())
.pipe(gulp.dest(distDir))

in package.json 在package.json中

"browser": "src/client/client",
"browserify": {
  "transform": [
    "coffee-reactify"
  ],
  "extension": [
    "cjsx",
    "coffee",
    "js",
    "json"
  ]
},

src/client/client.cjsx SRC /客户/ client.cjsx

otherModule = require './other-module' # other-module.cjsx
  1. When I remove coffee-reactify from transforms in package.json then browserify throws error Parsing file .../src/client/client.cjsx: Unexpected token (2:16) 当我从package.json中的transforms中删除coffee-reactify然后coffee-reactify抛出错误Parsing file .../src/client/client.cjsx: Unexpected token (2:16)

  2. When I put back coffee-reactify to transforms in package.json, then browserify successfully parses client.cjsx as long as I wont require any other .cjsx files from inside of client.cjsx . 当我放回coffee-reactifytransforms中的package.json,那么browserify成功解析client.cjsx只要我不会要求任何其他.cjsx从内部文件client.cjsx So for the example code of client.cjsx above browserify throws error: Cannot find module './other-module' from '/src/client - browserify still does not recognize extension... 因此对于client.cjsx上面的示例代码, Cannot find module './other-module' from '/src/client抛出错误: Cannot find module './other-module' from '/src/client - browserify仍然无法识别扩展名...

So browserify reads package.json (recognizes package.browserify.transforms and package.browser fields but it does not recognize extensions) 所以browserify读取package.json(识别package.browserify.transforms和package.browser字段,但它不识别扩展名)

We were running into the same problem. 我们遇到了同样的问题。 We were able to get it working by adding extensions to the browserify gulp function call. 我们能够通过添加browserify gulp函数调用的extensions来实现它。

browserify({
  entries: "src/index.coffee",
  extensions: [".cjsx", ".coffee", ".js", ".json" ]
})

We don't have it in the package.json at all, just in the gulp command. 我们根本没有在package.json中,只是在gulp命令中。

Try this: 尝试这个:

"browserify": {
  "transform": [
    "coffee-reactify"
  ],
  "extension": [ 
    "cjsx", 
    "coffee", 
    "js", 
    "json" 
  ]
},

Remove the . 删除. dots. 点。 Take a look at this question . 看看这个问题

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

相关问题 如何使用 angular 6 中的库发布指定已发布的 package.json? - How to specify published package.json with library publishing in angular 6? 如何在package.json文件中指定项目npm注册表 - How to specify project npm registry inside package.json file Browserify:如何使用package.json应用“ --exclude,-u”? - Browserify: How do I apply “--exclude, -u” using package.json? Browserify-在符号链接模块上的package.json中转换在npm3中不起作用 - Browserify - transform in package.json on symlinked modules not working in npm3 Yarn Workspaces和Browserify - 子文件夹中的package.json会破坏构建 - Yarn Workspaces and Browserify - package.json in subfolder breaks the build 如何在 package.json 中更改包的版本 - How to change the version of package in package.json 有没有办法在 package.json 文件中指定动态报告文件名? - Is there a way to specify a dynamic report filename in package.json file? 浏览包含package.json的文件夹时,Browserify会覆盖自己的配置吗? - Browserify overrides its own configuration when browsing a folder that contains a package.json? 使用带有grunt-browserify的shimmed package.json缓存的CKEditor资产 - CKEditor assets cached using shimmed package.json with grunt-browserify 如何在 package.json 中添加新脚本 - How to add a new script in package.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM