我正在使用一个使用webpack构建的chrome扩展。
我使用这个来构建:cross-env NODE_ENV=production yarn webpack -c webpack.config.js --mode production
webpack.config.js
const HTMLPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const BrowserExtensionPlugin = require("extension-build-webpack-plugin");
module.exports = {
entry: {
options: './src/options.tsx',
popup: './src/popup.tsx',
content: './src/content.tsx',
background: './src/background.tsx',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.css'],
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat',
},
},
module: {
rules: [
{
test: /\.(tsx|jsx|ts|js)x?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
],
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
],
},
plugins: [
new HTMLPlugin({
chunks: ['options'],
filename: 'options.html',
title: 'Options page title',
}),
new HTMLPlugin({
chunks: ['popup'],
filename: 'popup.html',
}),
new CopyPlugin([
{ from: './src/_locales/', to: './_locales' },
{ from: './src/assets', to: './assets' },
{ from: './src/manifest.json', to: './manifest.json' },
]),
new BrowserExtensionPlugin({devMode: false, name: "build/chromium.zip", directory: "src", updateType: "minor"}),
],
optimization: {
minimizer: [
new UglifyJSPlugin({
uglifyOptions: {
compress: {
drop_console: true,
drop_debugger: true,
}
}
})
]
},
mode: 'production',
stats: 'minimal',
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
}
};
manifest.json:
{
"manifest_version": 3,
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"default_locale": "en",
"version": "0.1.0",
....
....
}
如果我再次运行cross-env NODE_ENV=production yarn webpack -c webpack.config.js --mode production
,它会自动将version
从0.1.0
增加到0.2.0
,不仅在build
文件夹中,而且在src
文件夹中。我如何才能防止这种自动增量功能。我怀疑这是由于我使用的webpack插件之一。
1条答案
按热度按时间i7uq4tfw1#
这是由
extension-build-webpack-plugin
引起的,你真的不应该努力去寻找,因为总共有4个插件可以查看。不,它不提供任何避免版本颠簸的方法。只有当您希望它增加主版本号或次版本号(默认为次版本号)时,才可以进行配置。
这是一个使用起来非常奇怪的库,它很少被下载,而且没有维护。可能还有更好的选择。