[英]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
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)
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-reactify
到transforms
中的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.