webpack.conf.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const webpack = require('webpack');
  2. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
  3. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const BabiliWebpackPlugin = require('babili-webpack-plugin');
  6. const base = require('./webpack.base.conf');
  7. const { IS_DEV, merge } = require('./utils');
  8. const entry = {
  9. 'background/app': 'src/background/app.js',
  10. 'options/app': 'src/options/app.js',
  11. 'popup/app': 'src/popup/app.js',
  12. injected: 'src/injected/index.js',
  13. };
  14. module.exports = merge(base, {
  15. entry,
  16. plugins: [
  17. new webpack.optimize.CommonsChunkPlugin({
  18. name: 'browser',
  19. chunks: Object.keys(entry),
  20. }),
  21. new webpack.optimize.CommonsChunkPlugin({
  22. name: 'vendor',
  23. chunks: Object.keys(entry).filter(key => key !== 'injected'),
  24. minChunks: 2,
  25. }),
  26. new HtmlWebpackPlugin({
  27. filename: 'background/index.html',
  28. template: 'src/background/index.html',
  29. inject: true,
  30. chunks: ['vendor', 'browser', 'background/app'],
  31. chunksSortMode: 'dependency'
  32. }),
  33. new HtmlWebpackPlugin({
  34. filename: 'options/index.html',
  35. template: 'src/options/index.html',
  36. inject: true,
  37. chunks: ['vendor', 'browser', 'options/app'],
  38. chunksSortMode: 'dependency'
  39. }),
  40. new HtmlWebpackPlugin({
  41. filename: 'popup/index.html',
  42. template: 'src/popup/index.html',
  43. inject: true,
  44. chunks: ['vendor', 'browser', 'popup/app'],
  45. chunksSortMode: 'dependency'
  46. }),
  47. // new FriendlyErrorsPlugin(),
  48. ... IS_DEV ? [
  49. ] : [
  50. // extract css into its own file
  51. new ExtractTextPlugin('[name].css'),
  52. new BabiliWebpackPlugin(),
  53. ],
  54. ],
  55. externals: {
  56. localStorage: 'localStorage',
  57. },
  58. });