webpack.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const path = require('path');
  2. const glob = require('glob');
  3. var HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const config = {
  5. context: path.resolve(__dirname, './'),
  6. entry: {
  7. '0_vendor': require('./package.json').bundleDependencies,
  8. '1_app': './entry.js',
  9. '2_files': toArray(glob.sync('./app/**/*.js'), 'app.module.js'),
  10. },
  11. output: {
  12. filename: '[name].bundle.js'
  13. },
  14. devServer: {
  15. contentBase: path.join(__dirname, './'),
  16. compress: true,
  17. port: 9000,
  18. stats: 'errors-only',
  19. watchOptions: { aggregateTimeout: 300, poll: 1000 }
  20. },
  21. resolve: {
  22. alias: {
  23. 'node_modules': path.join(__dirname, 'node_modules'),
  24. }
  25. },
  26. plugins: [
  27. new HtmlWebpackPlugin({
  28. template: 'index.html',
  29. chunksSortMode: function(a, b) {
  30. return (a.names[0] > b.names[0])? 1 : -1;
  31. },
  32. inject: 'body',
  33. extraFiles: {
  34. css: './css/style.css'
  35. }
  36. })
  37. ],
  38. module: {
  39. rules: []
  40. }
  41. };
  42. module.exports = config;
  43. function toObject(paths) {
  44. var result = {};
  45. paths.forEach(function(path) {
  46. result[path.split('/').slice(-1)[0]] = path;
  47. });
  48. return result;
  49. }
  50. function toArray(paths, ignorePath) {
  51. var result = [];
  52. paths.forEach(function(path) {
  53. if (path.indexOf(ignorePath) !== -1) return;
  54. result.push(path);
  55. });
  56. return result;
  57. }