2020-10-26 15:18:23 +03:00
|
|
|
import path from 'path';
|
|
|
|
import webpack from 'webpack';
|
2020-11-17 01:53:51 +03:00
|
|
|
import CopyPlugin from 'copy-webpack-plugin';
|
2021-08-30 07:54:35 +03:00
|
|
|
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
const extpath = path.join(__dirname, '../src/browser/extension/');
|
2021-08-25 07:22:54 +03:00
|
|
|
const mock = `${extpath}chromeAPIMock`;
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
const baseConfig = (params) => ({
|
|
|
|
// devtool: 'source-map',
|
2021-06-20 06:08:00 +03:00
|
|
|
mode: params.mode,
|
2020-10-26 15:18:23 +03:00
|
|
|
entry: params.input || {
|
|
|
|
background: [mock, `${extpath}background/index`],
|
|
|
|
options: [mock, `${extpath}options/index`],
|
|
|
|
window: [`${extpath}window/index`],
|
|
|
|
remote: [`${extpath}window/remote`],
|
|
|
|
devpanel: [mock, `${extpath}devpanel/index`],
|
|
|
|
devtools: [`${extpath}devtools/index`],
|
|
|
|
content: [mock, `${extpath}inject/contentScript`],
|
|
|
|
pagewrap: [`${extpath}inject/pageScriptWrap`],
|
|
|
|
...params.inputExtra,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].bundle.js',
|
|
|
|
chunkFilename: '[id].chunk.js',
|
|
|
|
...params.output,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin(params.globals),
|
2021-08-30 07:54:35 +03:00
|
|
|
...(params.plugins
|
|
|
|
? params.plugins
|
|
|
|
: [
|
|
|
|
new ForkTsCheckerWebpackPlugin({
|
|
|
|
typescript: {
|
|
|
|
configFile: 'tsconfig.json',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]),
|
2020-11-17 01:53:51 +03:00
|
|
|
].concat(
|
|
|
|
params.copy
|
|
|
|
? new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
2020-11-17 04:20:57 +03:00
|
|
|
from: params.manifestJsonPath,
|
2020-11-17 01:53:51 +03:00
|
|
|
to: path.join(params.output.path, 'manifest.json'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../src/assets/'),
|
|
|
|
to: params.output.path,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
: []
|
|
|
|
),
|
2020-10-26 15:18:23 +03:00
|
|
|
optimization: {
|
2021-05-05 21:17:31 +03:00
|
|
|
minimize: false,
|
2020-10-26 15:18:23 +03:00
|
|
|
},
|
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
app: path.join(__dirname, '../src/app'),
|
|
|
|
tmp: path.join(__dirname, '../build/tmp'),
|
|
|
|
},
|
2021-08-25 07:22:54 +03:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
2021-08-29 07:09:37 +03:00
|
|
|
fallback: {
|
|
|
|
path: require.resolve('path-browserify'),
|
|
|
|
},
|
2020-10-26 15:18:23 +03:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
...(params.loaders
|
|
|
|
? params.loaders
|
|
|
|
: [
|
|
|
|
{
|
2021-08-25 07:22:54 +03:00
|
|
|
test: /\.(js|ts)x?$/,
|
2020-10-26 15:18:23 +03:00
|
|
|
use: 'babel-loader',
|
|
|
|
exclude: /(node_modules|tmp\/page\.bundle)/,
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
{
|
|
|
|
test: /\.css?$/,
|
2021-08-30 04:32:29 +03:00
|
|
|
use: ['style-loader', 'css-loader'],
|
2020-10-26 15:18:23 +03:00
|
|
|
},
|
2020-11-17 00:43:49 +03:00
|
|
|
{
|
|
|
|
test: /\.pug$/,
|
|
|
|
use: ['file-loader?name=[name].html', 'pug-html-loader'],
|
|
|
|
},
|
2020-10-26 15:18:23 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default baseConfig;
|