Require jsx files without specifying extension

前端 未结 1 720
悲&欢浪女
悲&欢浪女 2020-12-31 08:42

I am using browserify and watchify, and would like to require() files other than the default extensions .js and .json

1条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 09:09

    Edit (April 27, 2015): I just noticed that in the question, I had an invalid argument for extension, like so:

    "watch": "watchify ./src/App.js --extension=jsx -o dist/script.js -v -d"
    

    It should be (notice the . (dot) in --extension=.jsx):

    "watch": "watchify ./src/App.js --extension=.jsx -o dist/script.js -v -d"
    

    Original Answer:

    Adding in the browserify option to package.json did it for browserify but not for watchify.

    "scripts": {
      "build": "browserify ./src/App.js > dist/script.js -v -d",
      "watch": "watchify ./src/App.js -o dist/script.js -v -d"
    },
    "browserify": {
      "extension": [ "jsx" ],
      "transform": [ [ "reactify", { "es6": true } ] ]
    }
    

    Add in the extension option for the watch command made watchify work.

    "watch": "watchify ./src/App.js --extension=.jsx -o dist/script.js -v -d"
    

    However, non-DRY. I'd like to keep my commands short as possible, but ~oh well~.

    0 讨论(0)
提交回复
热议问题