webpack.conf.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
  4. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  5. const HtmlWebpackPlugin = require('html-webpack-plugin');
  6. const WrapperWebpackPlugin = require('wrapper-webpack-plugin');
  7. const base = require('./webpack.base.conf');
  8. const { isProd, merge, INIT_FUNC_NAME } = require('./utils');
  9. const entry = {
  10. 'background/app': './src/background/app.js',
  11. 'options/app': './src/options/app.js',
  12. 'confirm/app': './src/confirm/app.js',
  13. 'popup/app': './src/popup/app.js',
  14. injected: './src/injected/index.js',
  15. };
  16. const targets = [];
  17. module.exports = targets;
  18. targets.push(merge(base, {
  19. entry,
  20. plugins: [
  21. new webpack.optimize.CommonsChunkPlugin({
  22. name: 'common',
  23. chunks: Object.keys(entry).filter(name => name !== 'injected'),
  24. minChunks: (m, c) => c >= 2,
  25. }),
  26. new webpack.optimize.CommonsChunkPlugin({
  27. name: 'browser',
  28. chunks: ['common', 'injected'],
  29. minChunks: (m, c) => c >= 2,
  30. }),
  31. new HtmlWebpackPlugin({
  32. filename: 'background/index.html',
  33. chunks: ['browser', 'common', 'background/app'],
  34. }),
  35. new HtmlWebpackPlugin({
  36. filename: 'options/index.html',
  37. template: 'src/options/index.html',
  38. chunks: ['browser', 'common', 'options/app'],
  39. }),
  40. new HtmlWebpackPlugin({
  41. filename: 'confirm/index.html',
  42. template: 'src/confirm/index.html',
  43. chunks: ['browser', 'common', 'confirm/app'],
  44. }),
  45. new HtmlWebpackPlugin({
  46. filename: 'popup/index.html',
  47. template: 'src/popup/index.html',
  48. chunks: ['browser', 'common', 'popup/app'],
  49. }),
  50. // new FriendlyErrorsPlugin(),
  51. isProd && new ExtractTextPlugin('[name].css'),
  52. // new webpack.NormalModuleReplacementPlugin(/\.\/rules\.json$/, resource => {
  53. // resource.request = path.resolve(__dirname, '../src/resources/empty-rules.json');
  54. // }),
  55. ].filter(Boolean),
  56. }));
  57. targets.push(merge(base, {
  58. entry: {
  59. 'injected-web': './src/injected/web',
  60. },
  61. output: {
  62. libraryTarget: 'commonjs2',
  63. },
  64. plugins: [
  65. new WrapperWebpackPlugin({
  66. header: `\
  67. window.${INIT_FUNC_NAME} = function () {
  68. var module = { exports: {} };
  69. `,
  70. footer: `
  71. var exports = module.exports;
  72. return exports.__esModule ? exports['default'] : exports;
  73. };0;`,
  74. }),
  75. ],
  76. }));