简体   繁体   English

如何将 webpack 配置添加到单水疗中心生成的 webpack 配置文件 [single-spa+angular14]

[英]how to add webpack config to a single-spa generated webpack config file [single-spa+angular14]

how do i add the following configuration mentioned here to a single-spa generated webpack config file extra-webpack.config.js ?我如何将此处提到的以下配置添加到单水疗中心生成的 webpack 配置文件extra-webpack.config.js

 import linkerPlugin from '@angular/compiler-cli/linker/babel'; export default { //... module: { rules: [ { test: /\.m?js$/, use: { loader: 'babel-loader', options: { plugins: [linkerPlugin], compact: false, cacheDirectory: true, } } } ] } //... }

//extra-webpack.config.js (note the difernce in format) //extra-webpack.config.js (注意格式的不同)

 const singleSpaAngularWebpack = require('single-spa-angular/lib/webpack').default; module.exports = (config, options) => { const singleSpaWebpackConfig = singleSpaAngularWebpack(config, options); // Feel free to modify this webpack config however you'd like to~ singleSpaWebpackConfig.externals.push( ); return singleSpaWebpackConfig; };

Why am i trying this: to share an angular library with UI components in a single-spa framework with other angular micro apps.我为什么要尝试这个:与其他 angular 微应用程序共享一个angular library和一个single-spa框架中的 UI 组件。 The library will be loaded once via systemjs-importmap like documented in single-spa.该库将通过systemjs-importmap加载一次,如 single-spa 中所述。 this is the snippet from anuglar.json file for the library if useful如果有用,这是库的 anuglar.json 文件的片段

 "architect": {
    "build": {
      "builder": "@angular-builders/custom-webpack:browser",
      "options": {
        "outputPath": "dist",
        "index": "projects/my-lib/src/index.html",
        "main": "projects/my-lib/src/main.single-spa.ts",
        "customWebpackConfig": {
          "path": "projects/my-lib/extra-webpack.config.js",
          "libraryName": "@myOrg/my-lib",
          "libraryTarget": "system",
          "excludeAngularDependencies": true
        },
        "deployUrl": "http://localhost:4304/"
      },
      "configurations": {
        "production": {
          "tsConfig": "projects/my-lib/tsconfig.lib.prod.json"
        },
        "development": {
          "tsConfig": "projects/my-lib/tsconfig.lib.json"
        }
      },
      "defaultConfiguration": "production"
    },

Thanks谢谢

I figured out the way.我想出了办法。 althought it does not solve the original intent of my issue, the question here is answered.虽然没有解决我问题的初衷,但这里的问题得到了回答。

import pckg from 'single-spa-angular/lib/webpack';
import pckg1 from 'webpack-merge';
import linkerPlugin from '@angular/compiler-cli/linker/babel';
 

export default function (config, options) {
  const singleSpaWebpackConfig = pckg.default(config, options); 

  return pckg1.default(singleSpaWebpackConfig, {
    module: {
      rules: [
        {
          test: /\.js$/,
          use: {
            loader: 'babel-loader',
            options: {
              plugins: [linkerPlugin],
              compact: false,
              cacheDirectory: true,
            }
          }
        }
      ]
    }
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM