Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure a function similar to HtmlWebpackExternalsPlugin to inject files into a package? #8141

Open
moonsky-all opened this issue Oct 16, 2024 · 1 comment

Comments

@moonsky-all
Copy link

这是我们项目原来的代码

const HtmlWebpackExternalsPlugin = require('html-webpack-externals-plugin');

export default {
  // ...
  plugins: [
    new HtmlWebpackExternalsPlugin({
      externals: [
        {
          module: 'vue',
          entry: {
            path: process.env.NODE_ENV === 'production' ? 'dist/vue.min.js' : 'dist/vue.js',
            type: 'js',
          },
          global: 'Vue',
        },
        {
          module: 'vuex',
          entry: {
            path: process.env.NODE_ENV === 'production' ? 'dist/vuex.min.js' : 'dist/vuex.js',
            type: 'js',
          },
          global: 'Vuex',
        },
        {
          module: 'vue-router',
          entry: {
            path: process.env.NODE_ENV === 'production' ? 'dist/vue-router.min.js' : 'dist/vue-router.js',
            type: 'js',
          },
          global: 'VueRouter',
        },
        {
          module: '@asdc/ec-element',
          entry: ['lib/index.js', 'lib/theme-chalk/index.css'],
          supplements: ['lib/theme-chalk/fonts/'],
          global: 'EC_ELEMENT',
        },
        {
          module: 'axios',
          entry: {
            path: 'dist/axios.min.js',
          },
          global: 'axios',
        },
        {
          module: 'echarts',
          entry: [
            {
              path: 'dist/echarts.min.js',
              attributes: {
                async: '',
                // defer: '',
              },
            },
            {
              path: 'theme/macarons.js',
              attributes: {
                async: '',
                // defer: '',
              },
            },
          ],
          global: 'echarts',
          // append: true,
        },
        {
          module: 'lodash',
          entry: {
            path: 'lodash.min.js',
            type: 'js',
          },
          global: '_',
        },
      ],
    }),
  ],
  // ...
}

我们需要这个插件在编译时自动排除某些库,然后把库文件用 script 的方式自动注入到 index.html 中,但是我直接把这段代码复制到rsbuild.config.js tools.rspack#addPlugins( .. )中并没有生效

@chenjiahan chenjiahan changed the title 我想请问一下如何配置类似HtmlWebpackExternalsPlugin注入某个包内文件的功能? How to configure a function similar to HtmlWebpackExternalsPlugin to inject files into a package? Oct 16, 2024
@LingyuCoder
Copy link
Collaborator

HtmlWebpackExternalsPlugin had been deprecated. You can see the code of this plugin, it is just a combination of externals, CopyWebpackPlugin and HtmlWebpackIncludeAssetsPlugin(named html-webpack-tags-plugin now).

So you can use rspack.CopyRspackPlugin and html-rspack-tags-plugin instead to implement your own externals plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants