LoginSignup
18
18

More than 5 years have passed since last update.

node_modules以下でbrowserifyされる側が自分のtransformを指定する

Posted at

できないのかなーとTwitterで呟いたら@kumatch さんに教えてもらったので試してみた。

こんなファイル構成の時

index.js
package.json
node_modules/
  foo/
    index.js
    package.json

node_modules/foo/index.js はES6 moduleで書いて、babelでコンパイルして返したいようなケース。

node_modules/foo/index.js でbrowserify: {transform: ...} しておけば使ってくれる。

{
  "name": "foo",
  "version": "1.0.0",
  "main": "index.js",
  "browserify": {
    "transform": "babelify"
  }
}

自分がやったときはホスト側のbabelifyを使っていたけど、たぶんpackage.jsonのdependenciesにあれば使ってくれそうな気がする。(未検証)

flowtype

自分がやりたかったのは、flowtypeで書かれたモジュールを分割したかったのだけど、babelが一応superset的な位置にあるのでflowでチェックしつつ依存先との型を合わせるのは、うまく動いた。とはいえeslintないと辛そう。

18
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
18