2019-03-26 16:09:58 +01:00
|
|
|
require("dotenv").config()
|
|
|
|
|
2019-03-22 15:56:24 +01:00
|
|
|
const path = require("path")
|
|
|
|
const webpack = require("webpack")
|
2019-09-18 05:53:17 +02:00
|
|
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
|
2019-03-22 15:56:24 +01:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin")
|
|
|
|
const ZipPlugin = require("zip-webpack-plugin")
|
|
|
|
|
2020-06-05 09:52:44 +02:00
|
|
|
module.exports = (env) => {
|
2019-03-22 15:56:24 +01:00
|
|
|
const config = {
|
|
|
|
entry: {
|
|
|
|
background: "./src/js/background.js",
|
|
|
|
content: "./src/js/content.js",
|
|
|
|
popup: "./src/js/popup.js",
|
2019-05-24 13:34:15 +02:00
|
|
|
options: "./src/js/options.js",
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, `build/${env.browser}`),
|
2019-05-24 13:34:15 +02:00
|
|
|
filename: `[name].${process.env.npm_package_version}.js`,
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: [
|
|
|
|
{
|
2019-05-24 13:34:15 +02:00
|
|
|
loader: MiniCssExtractPlugin.loader,
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
|
|
|
"css-loader",
|
|
|
|
{
|
|
|
|
loader: "sass-loader",
|
|
|
|
options: {
|
2019-09-18 05:53:17 +02:00
|
|
|
sassOptions: {
|
|
|
|
includePaths: [path.join(__dirname, "src/css")],
|
|
|
|
},
|
2019-05-24 13:34:15 +02:00
|
|
|
},
|
|
|
|
},
|
2019-03-22 15:56:24 +01:00
|
|
|
],
|
2019-05-24 13:34:15 +02:00
|
|
|
exclude: /node_modules/,
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2019-05-24 13:34:15 +02:00
|
|
|
loader: "babel-loader",
|
|
|
|
},
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(jpg|png)$/,
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
2019-05-24 13:34:15 +02:00
|
|
|
name: "[path][name].[ext]",
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
2019-05-24 13:34:15 +02:00
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
2019-10-10 14:57:01 +02:00
|
|
|
{
|
|
|
|
test: /\.svg$/,
|
|
|
|
loader: "svg-inline-loader",
|
|
|
|
},
|
2019-05-24 13:34:15 +02:00
|
|
|
],
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
|
|
|
plugins: [
|
2019-09-19 09:19:48 +02:00
|
|
|
new CleanWebpackPlugin({
|
2020-06-15 17:14:31 +02:00
|
|
|
cleanAfterEveryBuildPatterns: ["!manifest.json", "!*.html"],
|
2019-09-19 09:19:48 +02:00
|
|
|
}),
|
2019-03-22 15:56:24 +01:00
|
|
|
new webpack.DefinePlugin({
|
2019-03-26 16:09:58 +01:00
|
|
|
"process.env.NODE_ENV": JSON.stringify(env.NODE_ENV),
|
2019-03-22 15:56:24 +01:00
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: "[name].css",
|
2019-05-24 13:34:15 +02:00
|
|
|
chunkFilename: "[id].css",
|
2019-03-22 15:56:24 +01:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.join(__dirname, "src", "background.html"),
|
2020-06-05 09:52:44 +02:00
|
|
|
filename: path.resolve(`build/${env.browser}`, "background.html"),
|
2019-05-24 13:34:15 +02:00
|
|
|
chunks: ["background"],
|
2019-03-22 15:56:24 +01:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.join(__dirname, "src", "popup.html"),
|
2020-06-05 09:52:44 +02:00
|
|
|
filename: path.resolve(`build/${env.browser}`, "popup.html"),
|
2019-05-24 13:34:15 +02:00
|
|
|
chunks: ["popup"],
|
2019-03-22 15:56:24 +01:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.join(__dirname, "src", "options.html"),
|
2020-06-05 09:52:44 +02:00
|
|
|
filename: path.resolve(`build/${env.browser}`, "options.html"),
|
2019-05-24 13:34:15 +02:00
|
|
|
chunks: ["options"],
|
|
|
|
}),
|
2019-03-22 15:56:24 +01:00
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
modules: [path.join(__dirname, "src/js"), "node_modules"],
|
|
|
|
alias: {
|
2019-05-24 13:34:15 +02:00
|
|
|
images: path.join(__dirname, "src/images"),
|
|
|
|
},
|
2019-03-22 15:56:24 +01:00
|
|
|
},
|
|
|
|
mode: env.NODE_ENV || "development",
|
2019-05-24 13:34:15 +02:00
|
|
|
devtool: "cheap-module-source-map",
|
2019-03-22 15:56:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (env.NODE_ENV === "production") {
|
2019-05-24 13:34:15 +02:00
|
|
|
config.devtool = "none"
|
2019-03-22 15:56:24 +01:00
|
|
|
config.plugins.push(
|
|
|
|
new ZipPlugin({
|
2019-05-24 13:34:15 +02:00
|
|
|
filename: `moco-bx-${env.browser}-v${process.env.npm_package_version}.zip`,
|
|
|
|
exclude: [/\.map$/],
|
|
|
|
}),
|
2019-03-22 15:56:24 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|