Code Monkey home page Code Monkey logo

Comments (5)

amireh avatar amireh commented on May 20, 2024

Is this a tested/support configuration?

First time I've heard about this feature, no I haven't really tested this.

Any ideas on what's happening?

It could be that if webpack is creating only 1 compiler for those builds then HappyPack will run only on the first build, because right now it's coded to stop after the initial build unless we're in watch mode (and in this case, we're not in watch mode, but there are two "initial" builds.)

That's just a wild guess though. We can take a look at this.

from happypack.

gnz00 avatar gnz00 commented on May 20, 2024

I'm not too familiar with the multi-compiler mode in Webpack, but if it helps at all, here is how I'm running concurrent builds (with HappyPack) for 12 different environments:

gulp.task('compile:all', function(done) {
  const promises = configs.map(
    config => new Promise((resolve, reject) => {
      webpack(config, (err, stats) => {
        if (err) reject(err);
        else resolve(stats)
      })
    })
  )

  Promise.all(promises)
  .then(stats => done(null))
  .catch(error => done(error))
})

There are some issues with process file limits on OS X. Might be worth looking into spawning child processes or some other workaround.

from happypack.

amireh avatar amireh commented on May 20, 2024

I've just tried this in a simple example and it seems to work fine for me. Make sure you're not using shared thread pools between the builds since each provides a different compiler and that won't work.

var path = require('path');
var HappyPack = require('../../');
var HAPPY_LOADER = path.resolve(__dirname, '../../loader.js');
var IDENTITY_LOADER = path.resolve(__dirname, './identity-loader.js');

module.exports = [
  {
    entry: path.resolve(__dirname, 'lib/a.js'),

    output: {
      path: path.resolve(__dirname, 'dist'),
      filename: '[name].js'
    },

    plugins: [
      new HappyPack({
        id: 'happy-build-1',
        loaders: [ IDENTITY_LOADER ],
        threads: 2
      })
    ],

    module: {
      loaders: [
        {
          test: /\.js$/,
          loader: HAPPY_LOADER + '?id=happy-build-1',
        }
      ]
    },
  },

  {
    entry: path.resolve(__dirname, 'lib/a.js'),

    output: {
      path: path.resolve(__dirname, 'dist-2'),
      filename: '[name].js'
    },

    plugins: [
      new HappyPack({
        id: 'happy-build-2',
        loaders: [ IDENTITY_LOADER ],
        threads: 2
      })
    ],

    module: {
      loaders: [
        {
          test: /\.js$/,
          loader: HAPPY_LOADER + '?id=happy-build-2',
        }
      ]
    },
  }
];

Closing this since I can't reproduce and no context was provided.

from happypack.

jmmendivil avatar jmmendivil commented on May 20, 2024

Here:

webpack.config.js

'use strict'
const path = require('path')
const webpack = require('webpack')
const commonConfig = require('./config.js')

let configs = []

const common = commonConfig()

const config1 = Object.assign(
  {},
  common,
  {
    entry: './app.coffee',
    output: {
      path: path.join(__dirname, 'dest'),
      filename: 'mobile.js' 
    },
    plugins: common.plugins.concat(
      new webpack.DefinePlugin({
        ENV: JSON.stringify('mobile')
      })
    )
  }
)

configs.push(config1)

const config2 = Object.assign(
  {},
  common,
  {
    entry: './app.coffee',
    output: {
      path: path.join(__dirname, 'dest'),
      filename: 'desktop.js' 
    },
    plugins: common.plugins.concat(
      new webpack.DefinePlugin({
        ENV: JSON.stringify('desktop')
      })
    )
  }
)
configs.push(config2)

module.exports = configs

config.js

'use strict'
const HappyPackPlugin = require('happypack')

module.exports = () => {
  return {
    module: {
      loaders: [
        { test: /\.coffee$/, loader: 'happypack/loader?id=coffeescript'  },
      ]
    },
    plugins: [
      new HappyPackPlugin({
        id: 'coffeescript',
        threads: 4,
        loaders: ['coffee-loader'],
        verbose: false
      })
    ]
  }
}

app.coffee

console.log 'ENV: ', ENV

expected: dist/mobile.js and dist/desktop.js

from happypack.

amireh avatar amireh commented on May 20, 2024

Try to avoid reusing the common config instance.. just create the common config twice since it's a factory anyway, a la:

const config1 = Object.assign({}, common(), { ... });
const config2 = Object.assign({}, common(), { ... });

Then you end up with 2 actually unique HappyPlugin instances as opposed to sharing one.

from happypack.

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.