webpack.conf.js 2.2 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. '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/public/index.html',
  47. chunks: ['browser', 'common', 'popup/app'],
  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. window.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. }));