【问题标题】:is it possible to let different entry package to different output path in webpack 5是否可以让不同的入口打包到 webpack 5 中的不同输出路径
【发布时间】:2022-01-28 19:29:57
【问题描述】:

我正在使用 webpack 打包一个 google chrome 扩展,我想将文件夹结构保留在 dist 文件夹中。例如,我想将所有弹出资源打包在dist/popup/*,这是我现在的配置:

const path = require('path');
const webpack = require( 'webpack' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin');
const HtmlWebpackPlugin = require( 'html-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
  entry : {
    popup : './src/popup/' 
  } ,
  resolve: {
    alias: {
        // https://stackoverflow.com/questions/50805384/module-not-found-error-cant-resolve-vue-path-not-correct
        vue: 'vue/dist/vue.esm-bundler.js'
    },
  },
  output : {
    path : path.resolve(__dirname, '../../bundle') ,
    filename : '[path]/[name].js'
  },
  module : {
    rules : [
      {
        test : /\.js$/ ,
        exclude : [ /node_modules(?!(\/|\\?\\)(translation\.js|selection-widget|connect\.io|chrome-env)\1)/ ] ,
        loader : 'babel-loader'
      } ,
      {
        test: /\.css$/i,
        use: [MiniCssExtractPlugin.loader, "css-loader"],
      },
      {
        test : /\.(scss)$/ ,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
      }
    ]
  },
  plugins : [
    new CopyPlugin({
      patterns: [
        { from: "src/manifest.json", to: "manifest.json" },
        { from: "src/resource/image", to: "resource/image" },
      ],
    }),
    new MiniCssExtractPlugin({
      filename: "[name].css",
      chunkFilename: "[id].css",
    }),
    new HtmlWebpackPlugin({
      filename: 'popup.html',
      template: 'src/popup/index.html'
    }),
    new webpack.DefinePlugin({
      __VUE_OPTIONS_API__: false,
      __VUE_PROD_DEVTOOLS__: false,
    }),
  ]
};

我尝试像这样调整输出文件名:

filename : '[path]/[name].js'

似乎没有用。我正在从谷歌搜索并没有找到任何建议。有可能这样做吗?或具有不同 dist 文件夹的不同条目。

【问题讨论】:

标签: javascript webpack


【解决方案1】:

我是这样定义条目的:

entry : {
    'popup/popup' : './src/popup/' 
  } ,

这将在 dist 中生成一个弹出文件夹。

【讨论】:

    猜你喜欢
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    相关资源
    最近更新 更多