webpack.conf.js 2.0 KB

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