webpack.conf.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 WrapperWebpackPlugin = require('wrapper-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. const targets = [];
  15. module.exports = targets;
  16. targets.push(merge(base, {
  17. entry,
  18. plugins: [
  19. new webpack.optimize.CommonsChunkPlugin({
  20. name: 'browser',
  21. chunks: Object.keys(entry),
  22. }),
  23. new webpack.optimize.CommonsChunkPlugin({
  24. name: 'vendor',
  25. chunks: Object.keys(entry).filter(key => key !== 'injected'),
  26. minChunks: 2,
  27. }),
  28. new HtmlWebpackPlugin({
  29. filename: 'background/index.html',
  30. template: 'src/background/index.html',
  31. inject: true,
  32. chunks: ['vendor', 'browser', 'background/app'],
  33. chunksSortMode: 'dependency'
  34. }),
  35. new HtmlWebpackPlugin({
  36. filename: 'options/index.html',
  37. template: 'src/options/index.html',
  38. inject: true,
  39. chunks: ['vendor', 'browser', 'options/app'],
  40. chunksSortMode: 'dependency'
  41. }),
  42. new HtmlWebpackPlugin({
  43. filename: 'popup/index.html',
  44. template: 'src/popup/index.html',
  45. inject: true,
  46. chunks: ['vendor', 'browser', 'popup/app'],
  47. chunksSortMode: 'dependency'
  48. }),
  49. // new FriendlyErrorsPlugin(),
  50. !IS_DEV && new ExtractTextPlugin('[name].css'),
  51. ].filter(Boolean),
  52. externals: {
  53. localStorage: 'localStorage',
  54. },
  55. }));
  56. targets.push(merge(base, {
  57. entry: {
  58. 'injected-web': 'src/injected/web',
  59. },
  60. output: {
  61. libraryTarget: 'commonjs2',
  62. },
  63. plugins: [
  64. new WrapperWebpackPlugin({
  65. header: `\
  66. var VM_initializeWeb = function () {
  67. var module = { exports: {} };
  68. `,
  69. footer: `
  70. var exports = module.exports;
  71. return exports.__esModule ? exports['default'] : exports;
  72. };`,
  73. }),
  74. ],
  75. }));