Giter Club home page Giter Club logo

Comments (2)

Traviskn avatar Traviskn commented on June 4, 2024

Hi @Morantron, we configured haul to have multiple entry points in order to support thread bundles.

Here's an example that's close to what we did in our webpack.haul.js. Some things that add complexity are that we have to alter the default config to not ignore node_modules, and we ended up needing to use a second config with custom scripts to build for release mode.

For development mode, this is our main haul config:

module.exports = (options, defaults) => {
  // Transform node_modules
  // See https://github.com/callstack/haul/issues/156
  defaults.module.rules[1].exclude = undefined;

  const entry = { [`index.${options.platform}`]: './index.js' };

  if (process.env.NODE_ENV === 'development') {
    entry['myworker.thread'] = './src/path/to/myworker.thread.js';
  }

  return {
    entry,
    output: {
      path: options.platform === 'ios'
        ? `${process.cwd()}/ios`
        : `${process.cwd()}/android/app/src/main/assets`,
      filename: '[name].bundle',
      publicPath: `http://localhost:${options.port}`,
    }
    module: { ...defaults.module },
  };
}

For building release thread bundles we use some custom npm scripts (you would run these before running the standard react native release build commands). In our package.json:

  "scripts": {
    "bundleThreadAndroid": "NODE_ENV=production haul bundle --platform android --dev false --minify true --assets-dest ./android/app/src/main/assets --bundle-output ./android/app/src/main/assets/threads/myworker.thread.bundle --config ./thread.webpack.haul.js",
    "bundleThreadIos": "NODE_ENV=production haul bundle --platform ios --dev false --minify true --assets-dest ./ios --bundle-output ./ios/myworker.thread.jsbundle --config ./thread.webpack.haul.js",
  }

Notice our thread bundling scripts use a separate haul config file, thread.webpack.haul.js, which looks like this:

module.exports = (options, defaults) => {
  // Transform node_modules
  // See https://github.com/callstack/haul/issues/156
  defaults.module.rules[1].exclude = undefined;

  return {
    entry: 'myworker.thread': './src/path/to/myworker.thread.js',
    output: {
      path: options.platform === 'ios'
        ? `${process.cwd()}/ios`
        : `${process.cwd()}/android/app/src/main/assets/threads/myworker.thread.bundle`,
      filename: 'myworker.thread.bundle',
      publicPath: `http://localhost:${options.port}`,
    },
    module: { ...defaults.module },
  };
}

I hope this is helpful, it ended up taking a bit of work to get the threads and haul working together 😅
I should probably also mention that we have not yet upgraded to the latest version of Haul, (we're on 1.0.0-beta.12) so there could be issues if you're using a different version.

from react-native-threads.

Traviskn avatar Traviskn commented on June 4, 2024

closing due to lack of response

from react-native-threads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.