<commit_before>const path = require('path')
const os = require('os')
const chalk = require('chalk')
const fs = require('fs-extra')

const isLocalPath = v => /^[./]|(^[a-zA-Z]:)/.test(v)

const normalizeEntry = v => {
  if (v.startsWith('module:')) {
    return v.replace(/^module:/, '')
  }
  if (isLocalPath(v)) {
    return v
  }
  return `./${v}`
}

module.exports = (config, api) => {
  /** Set entry */

  const webpackEntry = {}
  const { entry, pages } = api.config
  if (pages) {
    for (const entryName of Object.keys(pages)) {
      const value = pages[entryName]
      webpackEntry[entryName] = [].concat(
        typeof value === 'string' ? value : value.entry
      )
    }
    api.logger.debug('Using `pages` option thus `entry` is ignored')
  } else if (typeof entry === 'string') {
    webpackEntry.index = [entry]
  } else if (Array.isArray(entry)) {
    webpackEntry.index = entry
  } else if (typeof entry === 'object') {
    Object.assign(webpackEntry, entry)
  }

  for (const name of Object.keys(webpackEntry)) {
    webpackEntry[name] = Array.isArray(webpackEntry[name])
      ? webpackEntry[name].map(v => normalizeEntry(v))
      : normalizeEntry(webpackEntry[name])
  }

  config.merge({ entry: webpackEntry })

  /** Set extensions */
  config.resolve.extensions.merge(['.js', '.json', '.jsx', '.ts', '.tsx'])

  /** Support react-native-web by default, cuz why not? */
  // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
  config.resolve.alias
    .set('react-native', 'react-native-web')
    .set('#webpack-hot-client$', require.resolve('@poi/dev-utils/hotDevClient'))

  // output.sourceMap defaults to false in production mode
  config.devtool(
    api.config.output.sourceMap === false
      ? false
      : api.mode === 'production'
      ? 'source-map'
      : api.mode === 'test'
      ? 'cheap-module-eval-source-map'
      : 'cheap-module-source-map'
  )

  /** Alias @ to `src` folder since many apps store app code here */
  config.resolve.alias.set('@', api.resolveCwd('src'))

  /** Set mode */
  config.mode(api.mode === 'production' ? 'production' : 'development')

  config.merge({
    // Disable webpack's default minimizer
    // Minimization will be handled by mode:production plugin
    optimization: {<commit_msg>fix: include .wasm .mjs in resolve.extensions, closes #536<commit_after>const path = require('path')
const os = require('os')
const chalk = require('chalk')
const fs = require('fs-extra')

const isLocalPath = v => /^[./]|(^[a-zA-Z]:)/.test(v)

const normalizeEntry = v => {
  if (v.startsWith('module:')) {
    return v.replace(/^module:/, '')
  }
  if (isLocalPath(v)) {
    return v
  }
  return `./${v}`
}

module.exports = (config, api) => {
  /** Set entry */

  const webpackEntry = {}
  const { entry, pages } = api.config
  if (pages) {
    for (const entryName of Object.keys(pages)) {
      const value = pages[entryName]
      webpackEntry[entryName] = [].concat(
        typeof value === 'string' ? value : value.entry
      )
    }
    api.logger.debug('Using `pages` option thus `entry` is ignored')
  } else if (typeof entry === 'string') {
    webpackEntry.index = [entry]
  } else if (Array.isArray(entry)) {
    webpackEntry.index = entry
  } else if (typeof entry === 'object') {
    Object.assign(webpackEntry, entry)
  }

  for (const name of Object.keys(webpackEntry)) {
    webpackEntry[name] = Array.isArray(webpackEntry[name])
      ? webpackEntry[name].map(v => normalizeEntry(v))
      : normalizeEntry(webpackEntry[name])
  }

  config.merge({ entry: webpackEntry })

  /** Set extensions */
  config.resolve.extensions.merge([
    '.wasm',
    '.mjs',
    '.js',
    '.jsx',
    '.ts',
    '.tsx',
    '.json'
  ])

  /** Support react-native-web by default, cuz why not? */
  // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
  config.resolve.alias
    .set('react-native', 'react-native-web')
    .set('#webpack-hot-client$', require.resolve('@poi/dev-utils/hotDevClient'))

  // output.sourceMap defaults to false in production mode
  config.devtool(
    api.config.output.sourceMap === false
      ? false
      : api.mode === 'production'
      ? 'source-map'
      : api.mode === 'test'
      ? 'cheap-module-eval-source-map'
      : 'cheap-module-source-map'
  )

  /** Alias @ to `src` folder since many apps store app code here */
  config.resolve.alias.set('@', api.resolveCwd('src'))

  /** Set mode */
  config.mode(api.mode === 'production' ? 'production' : 'development')

  config.merge({
    // Disable webpack's default minimizer
    // Minimization will be handled by mode:production plugin
    optimization: {
{'fraction_non_alphanumeric': 0.17479847263470513, 'fraction_numerical': 0.003182011030971574, 'mean_word_length': 3.0611541774332474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1442755', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1541, 'n_words': 342}