问题
In 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...
in 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
"browser": "src/client/client",
"browserify": {
"transform": [
"coffee-reactify"
],
"extension": [
"cjsx",
"coffee",
"js",
"json"
]
},
src/client/client.cjsx
otherModule = require './other-module' # other-module.cjsx
When I remove
coffee-reactify
fromtransforms
in package.json then browserify throws errorParsing file .../src/client/client.cjsx: Unexpected token (2:16)
When I put back
coffee-reactify
totransforms
in package.json, then browserify successfully parsesclient.cjsx
as long as I wont require any other.cjsx
files from inside ofclient.cjsx
. So for the example code ofclient.cjsx
above browserify throws error:Cannot find module './other-module' from '/src/client
- browserify still does not recognize extension...
So browserify reads package.json (recognizes package.browserify.transforms and package.browser fields but it does not recognize extensions)
回答1:
We were running into the same problem. We were able to get it working by adding extensions
to the browserify
gulp function call.
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.
回答2:
Try this:
"browserify": {
"transform": [
"coffee-reactify"
],
"extension": [
"cjsx",
"coffee",
"js",
"json"
]
},
Remove the .
dots. Take a look at this question.
来源:https://stackoverflow.com/questions/30969318/how-to-specify-browserify-extensions-in-package-json