webpack.conf.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 base = require('./webpack.base.conf');
  6. const IS_DEV = process.env.NODE_ENV === 'development';
  7. const targets = module.exports = [];
  8. targets.push(Object.assign({}, base, {
  9. entry: {
  10. 'background/app': 'src/background/app.js',
  11. 'options/app': 'src/options/app.js',
  12. 'popup/app': 'src/popup/app.js',
  13. },
  14. plugins: [
  15. ... base.plugins,
  16. // split vendor js into its own file
  17. new webpack.optimize.CommonsChunkPlugin({
  18. name: 'vendor',
  19. minChunks: 2,
  20. }),
  21. new HtmlWebpackPlugin({
  22. filename: 'background/index.html',
  23. template: 'src/background/index.html',
  24. inject: true,
  25. chunks: ['vendor', 'background/app'],
  26. chunksSortMode: 'dependency'
  27. }),
  28. new HtmlWebpackPlugin({
  29. filename: 'options/index.html',
  30. template: 'src/options/index.html',
  31. inject: true,
  32. chunks: ['vendor', 'options/app'],
  33. chunksSortMode: 'dependency'
  34. }),
  35. new HtmlWebpackPlugin({
  36. filename: 'popup/index.html',
  37. template: 'src/popup/index.html',
  38. inject: true,
  39. chunks: ['vendor', 'popup/app'],
  40. chunksSortMode: 'dependency'
  41. }),
  42. // new FriendlyErrorsPlugin(),
  43. ... IS_DEV ? [
  44. ] : [
  45. // extract css into its own file
  46. new ExtractTextPlugin('[name].css'),
  47. new webpack.optimize.UglifyJsPlugin({
  48. compress: {
  49. warnings: false
  50. }
  51. }),
  52. ],
  53. ],
  54. externals: {
  55. localStorage: 'localStorage',
  56. },
  57. }));
  58. targets.push(Object.assign({}, base, {
  59. entry: {
  60. injected: 'src/injected.js',
  61. browser: 'src/browser.js',
  62. },
  63. plugins: [
  64. ... base.plugins,
  65. ... IS_DEV ? [] : [
  66. new webpack.optimize.UglifyJsPlugin({
  67. compress: {
  68. warnings: false
  69. }
  70. }),
  71. ],
  72. ],
  73. }));