mirror of
https://github.com/abhijithvijayan/web-extension-starter.git
synced 2026-03-20 01:37:46 +01:00
Add manifestDefaults for version
Also formatted by prettier.
This commit is contained in:
parent
2866b4632a
commit
062c27502f
@ -1,137 +1,145 @@
|
|||||||
const path = require('path');
|
const path = require("path");
|
||||||
const webpack = require('webpack');
|
const webpack = require("webpack");
|
||||||
const ZipPlugin = require('zip-webpack-plugin');
|
const ZipPlugin = require("zip-webpack-plugin");
|
||||||
const TerserPlugin = require('terser-webpack-plugin');
|
const TerserPlugin = require("terser-webpack-plugin");
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||||
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
|
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
|
||||||
const WebextensionPlugin = require('webpack-webextension-plugin');
|
const WebextensionPlugin = require("webpack-webextension-plugin");
|
||||||
|
|
||||||
|
const pkg = require("./package.json");
|
||||||
|
|
||||||
const targetBrowser = process.env.TARGET_BROWSER;
|
const targetBrowser = process.env.TARGET_BROWSER;
|
||||||
|
|
||||||
const getExtensionFileType = browser => {
|
const getExtensionFileType = browser => {
|
||||||
if (browser === 'opera') {
|
if (browser === "opera") {
|
||||||
return 'crx';
|
return "crx";
|
||||||
}
|
}
|
||||||
if (browser === 'firefox') {
|
if (browser === "firefox") {
|
||||||
return 'xpi';
|
return "xpi";
|
||||||
}
|
}
|
||||||
return 'zip';
|
return "zip";
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
mode: process.env.NODE_ENV === "production" ? "production" : "development",
|
||||||
context: path.resolve(__dirname, 'src'),
|
context: path.resolve(__dirname, "src"),
|
||||||
entry: {
|
entry: {
|
||||||
background: './scripts/background.js',
|
background: "./scripts/background.js",
|
||||||
contentScript: './scripts/contentScript.js',
|
contentScript: "./scripts/contentScript.js",
|
||||||
popup: './scripts/popup.js',
|
popup: "./scripts/popup.js",
|
||||||
options: './scripts/options.js',
|
options: "./scripts/options.js",
|
||||||
styles: ['./styles/popup.scss', './styles/options.scss'],
|
styles: ["./styles/popup.scss", "./styles/options.scss"]
|
||||||
},
|
},
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
filename: 'js/[name].bundle.js',
|
filename: "js/[name].bundle.js",
|
||||||
path: path.resolve(__dirname, 'extension', targetBrowser),
|
path: path.resolve(__dirname, "extension", targetBrowser)
|
||||||
},
|
},
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.ProgressPlugin(),
|
new webpack.ProgressPlugin(),
|
||||||
new FixStyleOnlyEntriesPlugin({ silent: true }),
|
new FixStyleOnlyEntriesPlugin({ silent: true }),
|
||||||
new webpack.EnvironmentPlugin(['NODE_ENV', 'TARGET_BROWSER']),
|
new webpack.EnvironmentPlugin(["NODE_ENV", "TARGET_BROWSER"]),
|
||||||
new CleanWebpackPlugin({
|
new CleanWebpackPlugin({
|
||||||
cleanOnceBeforeBuildPatterns: [
|
cleanOnceBeforeBuildPatterns: [
|
||||||
path.join(process.cwd(), `extension/${targetBrowser}`),
|
path.join(process.cwd(), `extension/${targetBrowser}`),
|
||||||
path.join(process.cwd(), `extension/${targetBrowser}.${getExtensionFileType(targetBrowser)}`),
|
path.join(
|
||||||
|
process.cwd(),
|
||||||
|
`extension/${targetBrowser}.${getExtensionFileType(targetBrowser)}`
|
||||||
|
)
|
||||||
],
|
],
|
||||||
cleanStaleWebpackAssets: false,
|
cleanStaleWebpackAssets: false,
|
||||||
verbose: true,
|
verbose: true
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'options.html',
|
template: "options.html",
|
||||||
// inject: false,
|
// inject: false,
|
||||||
chunks: ['options'],
|
chunks: ["options"],
|
||||||
filename: 'options.html',
|
filename: "options.html"
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'popup.html',
|
template: "popup.html",
|
||||||
// inject: false,
|
// inject: false,
|
||||||
chunks: ['popup'],
|
chunks: ["popup"],
|
||||||
filename: 'popup.html',
|
filename: "popup.html"
|
||||||
}),
|
}),
|
||||||
new CopyWebpackPlugin([{ from: 'assets', to: 'assets' }]),
|
new CopyWebpackPlugin([{ from: "assets", to: "assets" }]),
|
||||||
new WebextensionPlugin({ vendor: targetBrowser }),
|
new WebextensionPlugin({
|
||||||
|
vendor: targetBrowser,
|
||||||
|
manifestDefaults: { version: pkg.version }
|
||||||
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /.(js|jsx)$/,
|
test: /.(js|jsx)$/,
|
||||||
include: [path.resolve(__dirname, 'scripts')],
|
include: [path.resolve(__dirname, "scripts")],
|
||||||
loader: 'babel-loader',
|
loader: "babel-loader",
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
plugins: ['syntax-dynamic-import'],
|
plugins: ["syntax-dynamic-import"],
|
||||||
|
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
'@babel/preset-env',
|
"@babel/preset-env",
|
||||||
{
|
{
|
||||||
modules: false,
|
modules: false
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
],
|
]
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.scss$/,
|
test: /\.scss$/,
|
||||||
use: [
|
use: [
|
||||||
{
|
{
|
||||||
loader: 'file-loader',
|
loader: "file-loader",
|
||||||
options: {
|
options: {
|
||||||
name: '[name].css',
|
name: "[name].css",
|
||||||
context: './styles/',
|
context: "./styles/",
|
||||||
outputPath: 'css/',
|
outputPath: "css/"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
"extract-loader",
|
||||||
'extract-loader',
|
|
||||||
{
|
{
|
||||||
loader: 'css-loader',
|
loader: "css-loader",
|
||||||
options: {
|
options: {
|
||||||
sourceMap: true,
|
sourceMap: true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
loader: 'postcss-loader',
|
loader: "postcss-loader",
|
||||||
options: {
|
options: {
|
||||||
ident: 'postcss',
|
ident: "postcss",
|
||||||
// eslint-disable-next-line global-require
|
// eslint-disable-next-line global-require
|
||||||
plugins: [require('autoprefixer')()],
|
plugins: [require("autoprefixer")()]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
"resolve-url-loader",
|
||||||
'resolve-url-loader',
|
"sass-loader"
|
||||||
'sass-loader',
|
]
|
||||||
],
|
}
|
||||||
},
|
]
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
optimization: {
|
optimization: {
|
||||||
minimizer: [
|
minimizer: [
|
||||||
new TerserPlugin({
|
new TerserPlugin({
|
||||||
cache: true,
|
cache: true,
|
||||||
parallel: true,
|
parallel: true
|
||||||
}),
|
}),
|
||||||
new ZipPlugin({
|
new ZipPlugin({
|
||||||
path: path.resolve(__dirname, 'extension'),
|
path: path.resolve(__dirname, "extension"),
|
||||||
extension: `${getExtensionFileType(targetBrowser)}`,
|
extension: `${getExtensionFileType(targetBrowser)}`,
|
||||||
filename: `${targetBrowser}`,
|
filename: `${targetBrowser}`
|
||||||
}),
|
})
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
devServer: {
|
devServer: {
|
||||||
contentBase: path.join(__dirname, 'extension'),
|
contentBase: path.join(__dirname, "extension")
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user