0

Babel v6、react-intl v2、および webpack を使用して、ソース コードから JSON ファイルにメッセージを抽出したいと考えています。すべて正常にコンパイルされていますが、何も抽出されていません。react-intl の v2 を適切にメッセージを抽出するにはどうすればよいですか?

オプションがありますmessagesDir

私はもう試した:

{
  "extra": {
    "react-intl": {
      "messagesDir": "./i18n",
      "enforceDescriptions": true
    }
  }
}

webpack構成を使用

{ test: /\.js$/,
  loader: 'babel-loader',
  query: {
    // react needed for JSX syntax
    // es2015 needed for modules
    // stage0 needed to do splats (...variable)
    presets: ['react', 'es2015', 'stage-0'],
    // react-intl extracts i18n messages to a shared file
    // add-module-exports removes the need to do `require('a').default`
    plugins: ['react-intl', 'add-module-exports'],
    cacheDirectory: true
  },
  exclude: /node_modules|bower_components/
},

エラーメッセージとして「index.js: Unknown option: /.babelrc.extra」が表示されます。

extra上記のプロパティを上記の webpack 構成にも追加しようとしました。非常によく似たエラー メッセージが表示されます。

バージョン:

✗ npm ls | grep "intl"
├─┬ babel-plugin-react-intl@2.0.0
│ └── intl-messageformat-parser@1.2.0
├── intl@1.0.1
├── intl-locales-supported@1.0.0
├── intl-messageformat@1.2.0
├─┬ react-intl@2.0.0-pr-3
│ ├── intl-format-cache@2.0.4
4

1 に答える 1

2

答えは、非常にカスタムな webpack 構文を使用することです。

したがって、構文は次のとおりです。

5 plugins: [ - ['react-intl', { 6 'messagesDir': './i18n' 6 }], 'add-module-exports']

于 2016-01-16T18:50:33.460 に答える