How to specify browser extension in .json package?

In package.json:

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

      

When using the browser function it transform

works as expected, however the browser doesn't see the option extension(s)

- it throws an error and I need to pass the extension parameters manually to the browser ...


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"
  ]
},

      

Cci / client / client.cjsx

otherModule = require './other-module' # other-module.cjsx

      

  • When I remove coffee-reactify

    from transforms

    in package.json then loop through the error throwParsing file .../src/client/client.cjsx: Unexpected token (2:16)

  • When I return coffee-reactify

    to transforms

    in package.json, then the browser will parse successfully client.cjsx

    unless I need other .cjsx

    files from client.cjsx

    . So, for the example code client.cjsx

    above, the browser is throwing an error: Cannot find module './other-module' from '/src/client

    - the browser still doesn't recognize the extension ...

So the browser view reads package.json (recognizes package.browserify.transforms and package.browser but doesn't recognize extensions)

+3


source to share


2 answers


We faced the same problem. We were able to make it work by adding gulp extensions

to the function browserify

call.

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

      



We don't have it at package.json

all, just in the gulp command.

+1


source


Try the following:

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

      



Delete points .

. Take a look at this question .

0


source







All Articles