2019-02-20 08:10:03 +00:00
|
|
|
/* Copyright (c) 2018 Kamil Mikosz
|
|
|
|
* Copyright (c) 2019 Sienori
|
|
|
|
* Released under the MIT license.
|
|
|
|
* see https://opensource.org/licenses/MIT */
|
|
|
|
|
|
|
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
|
|
|
const {
|
|
|
|
getHTMLPlugins,
|
|
|
|
getOutput,
|
|
|
|
getCopyPlugins,
|
|
|
|
getZipPlugin,
|
|
|
|
getFirefoxCopyPlugins,
|
2021-05-30 09:52:52 +00:00
|
|
|
getMiniCssExtractPlugin,
|
2019-02-20 08:10:03 +00:00
|
|
|
getEntry
|
|
|
|
} = require("./webpack.utils");
|
|
|
|
const path = require("path");
|
|
|
|
const config = require("./config.json");
|
|
|
|
const CleanWebpackPlugin = require("clean-webpack-plugin");
|
2019-03-23 06:58:42 +00:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
2019-02-20 08:10:03 +00:00
|
|
|
|
2019-02-23 12:02:31 +00:00
|
|
|
const extVersion = require("./src/manifest-chrome.json").version;
|
|
|
|
const ffExtVersion = require("./src/manifest-firefox.json").version;
|
2019-02-20 08:10:03 +00:00
|
|
|
|
|
|
|
const generalConfig = {
|
|
|
|
mode: "production",
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2019-03-21 10:38:08 +00:00
|
|
|
src: path.resolve(__dirname, "src/"),
|
|
|
|
"webextension-polyfill": "webextension-polyfill/dist/browser-polyfill.min.js"
|
2019-02-20 08:10:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
loader: "babel-loader",
|
|
|
|
exclude: /node_modules/,
|
|
|
|
test: /\.(js|jsx)$/,
|
|
|
|
resolve: {
|
|
|
|
extensions: [".js", ".jsx"]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-05-02 14:31:11 +00:00
|
|
|
test: /\.(scss|css)$/,
|
2019-03-23 06:58:42 +00:00
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{
|
2021-05-16 12:03:33 +00:00
|
|
|
loader: "css-loader",
|
|
|
|
options: {
|
|
|
|
esModule: false
|
|
|
|
}
|
2019-03-23 06:58:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: "sass-loader"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2019-02-20 08:10:03 +00:00
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
use: [
|
|
|
|
"babel-loader",
|
|
|
|
{
|
|
|
|
loader: "react-svg-loader",
|
|
|
|
options: {
|
|
|
|
svgo: {
|
|
|
|
plugins: [{ removeTitle: false }],
|
|
|
|
floatPrecision: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = [
|
|
|
|
{
|
|
|
|
...generalConfig,
|
|
|
|
output: getOutput("chrome", config.tempDirectory),
|
|
|
|
entry: getEntry(config.chromePath),
|
2020-05-01 16:00:51 +00:00
|
|
|
optimization: {
|
|
|
|
minimize: true
|
|
|
|
},
|
2019-02-20 08:10:03 +00:00
|
|
|
plugins: [
|
|
|
|
new CleanWebpackPlugin(["dist", "temp"]),
|
2021-05-30 09:52:52 +00:00
|
|
|
...getMiniCssExtractPlugin(),
|
2019-02-20 08:10:03 +00:00
|
|
|
...getHTMLPlugins("chrome", config.tempDirectory, config.chromePath),
|
|
|
|
...getCopyPlugins("chrome", config.tempDirectory, config.chromePath),
|
|
|
|
getZipPlugin(`${config.extName}-for-chrome-${extVersion}`, config.distDirectory)
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...generalConfig,
|
|
|
|
entry: getEntry(config.firefoxPath),
|
|
|
|
output: getOutput("firefox", config.tempDirectory),
|
2020-05-01 16:00:51 +00:00
|
|
|
optimization: {
|
|
|
|
minimize: true
|
|
|
|
},
|
2019-02-20 08:10:03 +00:00
|
|
|
plugins: [
|
|
|
|
new CleanWebpackPlugin(["dist", "temp"]),
|
2021-05-30 09:52:52 +00:00
|
|
|
...getMiniCssExtractPlugin(),
|
2019-02-20 08:10:03 +00:00
|
|
|
...getHTMLPlugins("firefox", config.tempDirectory, config.firefoxPath),
|
|
|
|
...getFirefoxCopyPlugins("firefox", config.tempDirectory, config.firefoxPath),
|
|
|
|
getZipPlugin(`${config.extName}-for-firefox-${ffExtVersion}`, config.distDirectory)
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: "production",
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
src: path.resolve(__dirname, "src/")
|
|
|
|
}
|
|
|
|
},
|
2019-02-23 12:02:31 +00:00
|
|
|
entry: { other: path.resolve(__dirname, `src/background/background.js`) },
|
2019-02-20 08:10:03 +00:00
|
|
|
output: getOutput("copiedSource", config.tempDirectory),
|
|
|
|
plugins: [
|
2021-04-06 08:52:14 +00:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: `src`,
|
2021-09-08 17:02:24 +00:00
|
|
|
to: path.resolve(__dirname, `${config.tempDirectory}/copiedSource/src/`),
|
|
|
|
info: { minimized: true }
|
2021-04-06 08:52:14 +00:00
|
|
|
},
|
|
|
|
{
|
2021-09-08 17:06:08 +00:00
|
|
|
from: "*",
|
|
|
|
to: path.resolve(__dirname, `${config.tempDirectory}/copiedSource/`),
|
|
|
|
globOptions: {
|
|
|
|
ignore: ["**/BACKERS.md", "**/crowdin.yml"]
|
|
|
|
}
|
2021-04-06 08:52:14 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
2020-05-01 16:41:25 +00:00
|
|
|
getZipPlugin(`copiedSource-${config.extName}-${ffExtVersion}`, config.distDirectory, "other/")
|
2019-02-20 08:10:03 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|