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