最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Webpack not exposing all the package.json dependencies in the generated library ( browser code ) - Stack Overflow

programmeradmin3浏览0评论

I have a webpack config to bundle all the node_modules dependencies mentioned in the package.json file. The following config file generates a library which exposes only the last mentioned in dependency in dependencies list.

const { webpack, ProvidePlugin } = require("webpack");
const { dependencies } = require('./package.json');
const path = require('path');

const provideConfig = {};
Object.keys(dependencies).forEach(dep=>{
    provideConfig[dep] = dep;
});

module.exports = {
   mode: "development",
   target: ['web','es5'],
   entry:{
       vendor: Object.keys(dependencies) // Create a separate entry for each dependency
   },
   output:{
      filename: 'bundle.js',
      path: path.resolve(__dirname, '.'),
      library: 'myLibrary',
      libraryTarget: 'umd'
   },
   plugins: [
      new ProvidePlugin(providePlugin)
   ],
   devtool: 'source-map'
};

I am expecting this to expose the the dependency as, myLibrary.<dependency_name>

This is only exposing the last dependency in dependencies list of package.json

I am using webpack 5.98

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论