Skip to content

Instantly share code, notes, and snippets.

@javan
Created May 30, 2018 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javan/cedb782b697c929862ceb08d0dd74ee0 to your computer and use it in GitHub Desktop.
Save javan/cedb782b697c929862ceb08d0dd74ee0 to your computer and use it in GitHub Desktop.
Ideas for improving webpack.config.js

This is the example webpack.config.js on https://webpack.js.org/:

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  }
}

Why is entry a relative file path and output an object with an absolute directory path and filename? Make them consistent:

module.exports = {
  entry: './src/index.js',
  output: './dist/bundle.js'
}

// Or

module.exports = {
  entry: {
    path: path.resolve(__dirname, 'src')
    filename: 'index.js'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  }
}

Both entry and output are reasonable option names, but their relationship is unclear. Antonyms would be better:

module.exports = {
  entry: './src/index.js',
  exit: './dist/bundle.js'
}

// Or

module.exports = {
  enter: './src/index.js',
  exit: './dist/bundle.js'
}

// Or

module.exports = {
  input: './src/index.js',
  output: './dist/index.js'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment