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.

78 lines
2.5 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 localePackPaths = require('./generateLocalePacks');
  12. const extensionGlob = `**/*{${paths.extensions.join(',')}}*`;
  13. const packPaths = sync(join(paths.source, paths.entry, extensionGlob));
  14. const entryPacks = [].concat(packPaths).concat(localePackPaths);
  15. module.exports = {
  16. entry: entryPacks.reduce(
  17. (map, entry) => {
  18. const localMap = map;
  19. let namespace = relative(join(paths.source, paths.entry), dirname(entry));
  20. if (namespace === '../../../tmp/packs') {
  21. namespace = ''; // generated by generateLocalePacks.js
  22. }
  23. localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
  24. return localMap;
  25. }, {}
  26. ),
  27. output: {
  28. filename: '[name].js',
  29. chunkFilename: '[name]-[chunkhash].js',
  30. path: resolve(paths.output, paths.entry),
  31. publicPath,
  32. },
  33. module: {
  34. rules: sync(join(loadersDir, '*.js')).map(loader => require(loader)),
  35. },
  36. plugins: [
  37. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  38. new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
  39. new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }),
  40. new webpack.optimize.CommonsChunkPlugin({
  41. name: 'common',
  42. minChunks: (module, count) => {
  43. if (module.resource && /node_modules\/react-intl/.test(module.resource)) {
  44. // skip react-intl because it's useless to put in the common chunk,
  45. // e.g. because "shared" modules between zh-TW and zh-CN will never
  46. // be loaded together
  47. return false;
  48. }
  49. return count >= 2;
  50. },
  51. }),
  52. ],
  53. resolve: {
  54. extensions: paths.extensions,
  55. modules: [
  56. resolve(paths.source),
  57. resolve(paths.node_modules),
  58. ],
  59. },
  60. resolveLoader: {
  61. modules: [paths.node_modules],
  62. },
  63. node: {
  64. // Called by http-link-header in an API we never use, increases
  65. // bundle size unnecessarily
  66. Buffer: false,
  67. },
  68. };