| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- const path = require('path');
- const webpack = require('webpack');
- const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
- const ExtractTextPlugin = require('extract-text-webpack-plugin');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const WrapperWebpackPlugin = require('wrapper-webpack-plugin');
- const base = require('./webpack.base.conf');
- const { isProd, merge, INIT_FUNC_NAME } = require('./utils');
- const entry = {
- 'background/app': './src/background/app.js',
- 'options/app': './src/options/app.js',
- 'confirm/app': './src/confirm/app.js',
- 'popup/app': './src/popup/app.js',
- injected: './src/injected/index.js',
- };
- const targets = [];
- module.exports = targets;
- targets.push(merge(base, {
- entry,
- plugins: [
- new webpack.optimize.CommonsChunkPlugin({
- name: 'common',
- chunks: Object.keys(entry).filter(name => name !== 'injected'),
- minChunks: (m, c) => c >= 2,
- }),
- new webpack.optimize.CommonsChunkPlugin({
- name: 'browser',
- chunks: ['common', 'injected'],
- minChunks: (m, c) => c >= 2,
- }),
- new HtmlWebpackPlugin({
- filename: 'background/index.html',
- chunks: ['browser', 'common', 'background/app'],
- }),
- new HtmlWebpackPlugin({
- filename: 'options/index.html',
- template: 'src/options/index.html',
- chunks: ['browser', 'common', 'options/app'],
- }),
- new HtmlWebpackPlugin({
- filename: 'confirm/index.html',
- template: 'src/confirm/index.html',
- chunks: ['browser', 'common', 'confirm/app'],
- }),
- new HtmlWebpackPlugin({
- filename: 'popup/index.html',
- template: 'src/popup/index.html',
- chunks: ['browser', 'common', 'popup/app'],
- }),
- // new FriendlyErrorsPlugin(),
- isProd && new ExtractTextPlugin('[name].css'),
- // new webpack.NormalModuleReplacementPlugin(/\.\/rules\.json$/, resource => {
- // resource.request = path.resolve(__dirname, '../src/resources/empty-rules.json');
- // }),
- ].filter(Boolean),
- }));
- targets.push(merge(base, {
- entry: {
- 'injected-web': './src/injected/web',
- },
- output: {
- libraryTarget: 'commonjs2',
- },
- plugins: [
- new WrapperWebpackPlugin({
- header: `\
- window.${INIT_FUNC_NAME} = function () {
- var module = { exports: {} };
- `,
- footer: `
- var exports = module.exports;
- return exports.__esModule ? exports['default'] : exports;
- };0;`,
- }),
- ],
- }));
|