闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

  1. // Note: You must restart bin/webpack-dev-server for changes to take effect
  2. /* eslint global-require: 0 */
  3. /* eslint import/no-dynamic-require: 0 */
  4. const webpack = require('webpack')
  5. const { basename, dirname, join, relative, resolve } = require('path')
  6. const { sync } = require('glob')
  7. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  8. const ManifestPlugin = require('webpack-manifest-plugin')
  9. const extname = require('path-complete-extname')
  10. const { env, paths, publicPath, loadersDir } = require('./configuration.js')
  11. const extensionGlob = `**/*{${paths.extensions.join(',')}}*`
  12. const packPaths = sync(join(paths.source, paths.entry, extensionGlob))
  13. module.exports = {
  14. entry: packPaths.reduce(
  15. (map, entry) => {
  16. const localMap = map
  17. const namespace = relative(join(paths.source, paths.entry), dirname(entry))
  18. localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry)
  19. return localMap
  20. }, {}
  21. ),
  22. output: {
  23. filename: '[name].js',
  24. chunkFilename: '[name]-[chunkhash].js',
  25. path: resolve(paths.output, paths.entry),
  26. publicPath
  27. },
  28. module: {
  29. rules: sync(join(loadersDir, '*.js')).map(loader => require(loader))
  30. },
  31. plugins: [
  32. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  33. new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
  34. new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }),
  35. new webpack.optimize.CommonsChunkPlugin({
  36. name: 'vendor',
  37. minChunks: ({ resource }) => /node_modules/.test(resource)
  38. })
  39. ],
  40. resolve: {
  41. extensions: paths.extensions,
  42. modules: [
  43. resolve(paths.source),
  44. resolve(paths.node_modules)
  45. ]
  46. },
  47. resolveLoader: {
  48. modules: [paths.node_modules]
  49. },
  50. node: {
  51. // Called by http-link-header in an API we never use, increases
  52. // bundle size unnecessarily
  53. Buffer: false
  54. }
  55. }