webpack.config.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // 'style': './css/style.scss'
  11. },
  12. output: {
  13. filename: '[name].bundle.js'
  14. },
  15. devServer: {
  16. contentBase: path.join(__dirname, './'),
  17. compress: true,
  18. port: 9000,
  19. stats: 'errors-only',
  20. watchOptions: { aggregateTimeout: 300, poll: 1000 }
  21. },
  22. resolve: {
  23. alias: {
  24. 'node_modules': path.join(__dirname, 'node_modules'),
  25. }
  26. },
  27. plugins: [
  28. new HtmlWebpackPlugin({
  29. template: 'index.html',
  30. chunksSortMode: function(a, b) {
  31. return (a.names[0] > b.names[0])? 1 : -1;
  32. },
  33. inject: 'body',
  34. extraFiles: {
  35. css: './css/style.css'
  36. }
  37. })
  38. ],
  39. module: {
  40. rules: [
  41. // {test: /\.css$/, use: ['style-loader', 'css-loader']}
  42. /*{
  43. test: /\.(s*)css$/,
  44. use: [
  45. 'style-loader', // creates style nodes from JS strings
  46. 'css-loader', // translates CSS into CommonJS
  47. 'sass-loader' // compiles Sass to CSS
  48. ]
  49. }*/
  50. ]
  51. }
  52. };
  53. module.exports = config;
  54. function toObject(paths) {
  55. var result = {};
  56. paths.forEach(function(path) {
  57. result[path.split('/').slice(-1)[0]] = path;
  58. });
  59. return result;
  60. }
  61. function toArray(paths, ignorePath) {
  62. var result = [];
  63. paths.forEach(function(path) {
  64. if (path.indexOf(ignorePath) !== -1) return;
  65. result.push(path);
  66. });
  67. return result;
  68. }