是否可以使用Web Pack为ReactNative组件创建bundle.js?

时间:2019-08-28 06:43:28

标签: react-native webpack

是否可以为React Native组件配置webpack? 并从webpack捆绑包中将该组件导入React Native Project

1 个答案:

答案 0 :(得分:0)

您可以通过React-native-webpack模块使用它。这是一个配置示例。

安装

npm install webpack json-loader clean-webpack-plugin react-native-webpack --save
npm install webpack-dev-server --save-dev

示例配置

global.__PLATFORM__ = process.env.RN_PLATFORM || 'ios';

module.exports = {
  context: __dirname,
  entry: {
    index: [
      'react-native-webpack/clients/polyfills.js',
      `./index.${__PLATFORM__}.js`,
    ],
  },
  output: {
    path: assetsPath,
    filename: `[name].${__PLATFORM__}.bundle`,
    chunkFilename: '[name].chunk.js',
    publicPath: '/',
  },
  devServer: {
    port: 8081,
    quiet: false,
    noInfo: true,
    lazy: true,
    filename: `[name].${__PLATFORM__}.bundle`,
    watchOptions: {
      aggregateTimeout: 300,
      poll: 1000,
    },
    publicPath: '/',
    stats: { colors: true },
  },
};