{"size": 938, "ext": "js", "max_stars_repo_path": "src/features/webpack/src/index.js", "max_stars_repo_name": "skypager/skypager-next", "max_stars_repo_stars_event_min_datetime": "2016-09-30T07:00:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-04T16:25:13.000Z", "max_issues_repo_path": "src/features/webpack/src/index.js", "max_issues_repo_name": "skypager/skypager-next", "max_issues_repo_issues_event_min_datetime": "2017-12-13T06:27:00.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-16T18:04:56.000Z", "max_forks_repo_path": "src/features/webpack/src/index.js", "max_forks_repo_name": "skypager/skypager-next", "max_forks_repo_forks_event_min_datetime": "2018-12-12T19:58:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-02T09:10:34.000Z"}
{"max_stars_count": 31, "max_issues_count": 13, "max_forks_count": 7, "avg_line_length": 25.3513513514, "max_line_length": 121, "alphanum_fraction": 0.6950959488}
import runtime, { Feature } from '@skypager/node'
import webpack from 'webpack'
import configMerge from 'webpack-merge'

runtime.features.register('webpack', () => WebpackFeature)

/**
 * The Browser VM Feature provides a JSDOM sandbox that lets you use the runtime.vm as if it was really inside a browser.
 *
 * This lets you run browser scripts in node, for testing, server rendering, whatever.
 *
 * @export
 * @class BrowserVmFeature
 * @extends {Feature}
 */
export default class WebpackFeature extends Feature {
  static isCacheable = false
  static isObservable = true
  static allowAnonymousProviders = true

  initialState = {
    progress: 0,
    stage: 'Created',
  }

  createCompiler(config) {
    const compiler = webpack(config)

    compiler.runAsync = options =>
      new Promise((resolve, reject) =>
        compiler.run(options, (err, stats) => (err ? reject(err) : resolve(stats)))
      )

    return compiler
  }
}
