nuxt.config.js 配合微前端qiankun打包配置


const CompressionPlugin = require('compression-webpack-plugin')
const timeStamp = new Date().getTime();
export default {
  /*
   ** Nuxt rendering mode
   ** See https://nuxtjs.org/api/configuration-mode
   */
  mode: 'spa',
  ssr: false,
  /*
   ** Nuxt target
   ** See https://nuxtjs.org/api/configuration-target
   */
  target: 'server',
  // 不参与nuxt数据收集
  telemetry: false,
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' },
    ],
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    '~/assets/css/element-variables.scss',
    '~/assets/css/base.scss',
    '~/assets/css/page.scss',
  ],

  styleResources: {
    scss: '@/assets/css/variables.scss',
  },

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    '@/plugins/element-ui',
    '@/plugins/axios',
    '@/plugins/common',
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/eslint
    // '@nuxtjs/eslint-module',
    // https://go.nuxtjs.dev/stylelint
    // '@nuxtjs/stylelint-module',
    "@nuxtjs/style-resources",
  ],

  router: {
    routeNameSplitter: '/',
  },

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    '@femessage/nuxt-micro-frontend',
    'cookie-universal-nuxt',
  ],

  MFE: {
    force: true
  },

  server: {
    host: '0.0.0.0',
    port: '15008',
  },

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    proxy: true,
    // prefix: '/api',
    retry: { retries: 3 },
    common: {
      contentType: 'application/json',
    },
  },

  proxy: {
    '/api/': {
      target: process.env.baseUrl || 'http://127.0.0.1:30080',
      secure: false,
      logLevel: 'debug',
      pathRewrite: {
        '^/api': '',
        changeOrigin: true,
      },
      xfwd: false,
    },
  },
  generate: {
    fallback: 'index.html',
    dir: 'dist/h-rad-engine/',
  },
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    transpile: [/^element-ui/],
    publicPath: '/microapps/h-rad-engine',
    optimization: {
      splitChunks: {
        minSize: 30000,
        maxSize: 250000,
      },
    },
    extend(config, { isDev, isClient, isServer }) {
      config.output.filename = `js/[name].${timeStamp}.js`
      config.output.chunkFilename = `js/chunk.[id].${timeStamp}.js`
    },
    plugins: [
      new CompressionPlugin({
        filename: '[path].gz[query]', //  使得多个.gz文件合并成一个文件,这种方式压缩后的文件少
        test: /\.js$|\.html$|\.css|png|svg|jpg|jpeg/, // 匹配文件名
        threshold: 10240, // 对超过10kb的数据进行压缩
        deleteOriginalAssets: false, // 是否删除原文件
      }),
    ],
    configureWebpack: {
      output: {
        // 微应⽤的包名,这⾥与主应⽤中注册的微应⽤名称⼀致
        library: 'h-rad-engine',
        // 将你的 library 暴露为所有的模块定义下都可运⾏的⽅式
        libraryTarget: 'umd',
        // 按需加载相关,设置为 webpackJsonp_微应⽤名称 即可
        chunkLoadingGlobal: `webpackJsonp_h-rad-engine`,
      },
    },
  },
}

你可能感兴趣的:(前端,javascript,开发语言)