阻止Webpack自动递增项目版本

huangapple go评论58阅读模式
英文:

Prevent webpack from auto-incrementing project version

问题

以下是您要翻译的内容:

"我正在使用一个 Chrome 扩展,该扩展使用 webpack 进行构建。

要构建,我使用以下命令: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,它会自动将version0.1.0增加到0.2.0,不仅在build文件夹中,还在src文件夹中。我怀疑这是由于我使用的 webpack 插件之一引起的。"

英文:

I am working with a chrome extension which uses webpack to build.

To build I use this : 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",
    ....
    ....
}

If I run cross-env NODE_ENV=production yarn webpack -c webpack.config.js --mode production again it increments the version from 0.1.0 to 0.2.0 automatically not just in build folder but in src folder as well. How can I prevent this auto increment functionality.
I suspect it's due to one of the webpack plugins I am using.

答案1

得分: 0

这是由 extension-build-webpack-plugin 引起的,你真的不应该为找到它而苦苦挣扎,因为那里总共有 4 个插件可以查看。

不,它不提供任何避免版本升级的方法。你只能配置是否要将主要版本或次要版本号提升,默认为次要版本

这是一个非常奇怪的库,它的下载量很少并且没有维护。可能有更好的替代方案。

英文:

This is caused by extension-build-webpack-plugin which you really shouldn't have struggled to find, as there's a total of 4 plugins there to look at.

No, it does not offer any method of avoiding version bumps. You can only configure if you want it to bump the major or minor version number, defaulting to minor.

It's a really weird library to be using, it gets few downloads and is unmaintained. There's probably better alternatives out there.

huangapple
  • 本文由 发表于 2023年6月1日 10:45:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定