基于create-react-app进行多入口项目配置

1. 安装 create-react-app就不说了,可以自行按照官网指导操作;

https://react.docschina.org/docs/create-a-new-react-app.html

npm create-react-app my-app
cd my-app
npm start

2. 安装完成后,执行 

npm run eject  

3. 完成后配置\config\webpack.config.js文件,修改入口和出口;

// 入口参数配置,出口为 【入口的key】.html
const entryParams = {
  pageOne: [
    paths.appSrc + "/pageOne/index.js",
  ],
  pageTwo: [
    paths.appSrc + "/pageTwo/index.js",
  ]
};
// This is the production and development configuration.
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
module.exports = function (webpackEnv) {
  const isEnvDevelopment = webpackEnv === 'development';
  const isEnvProduction = webpackEnv === 'production';
  let enterObjKeys = Object.keys(entryParams) || [];
  // 入口参数组装  出口参数组装
  let outParams = [];
  enterObjKeys.forEach(item => {
    entryParams[item].unshift(require.resolve('react-dev-utils/webpackHotDevClient'));
    outParams.push(isEnvProduction && new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml,
      chunks: [item],
      filename: item + '.html',
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeEmptyAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true,
      }
    }));
  });
plugins: [
      isEnvDevelopment &&
      new HtmlWebpackPlugin(
        {
          inject: true,
          template: paths.appHtml,
          chunks: ["index"],
          filename: 'index.html',
        }),
      ...outParams,

 

具体配置代码,请访问

create-react-app-multiple-entry-config

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值