在一个或多个条目上配置 [英] Config on one or more entry

查看:22
本文介绍了在一个或多个条目上配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对一些条目应用优化,而不是全部.

I want to apply optimization on some entries, not all.

有办法吗?

例如:

const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
  entry: {
    app: './src/client.js',
    server: './src/server.js',
  },
  output: {
    path: __dirname + '/dist',
    chunkFilename: '[name].chunk.js'
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ['babel-loader']
      },
      {
        test: /\.css$/,
        loader:['style-loader', 'css-loader']
      },
      {
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [
          'file-loader',
          {
            loader: 'image-webpack-loader',
          },
        ],
      },
    ]
  },
  resolve: {
    extensions: ['*', '.js', '.jsx']
  },
  plugins: [
    new webpack.ProgressPlugin(),
    new CleanWebpackPlugin(),
    new CopyPlugin([
      { from: 'public/index.html' },
    ])
  ],
  devtool: 'inline-source-map',
  optimization: {
    splitChunks: {
      chunks: 'all',
    },
    runtimeChunk: {
      name: entrypoint => `runtime_${entrypoint.name}`,
    },
  },
  devServer: {
    publicPath: '/dist',
    contentBase: __dirname + '/dist',
    hot: true,
  }
};

我只想在客户端(应用程序)条目上应用优化,而不是在服务器上.

I want to apply optimization only on client (app) entry, not on server.

我可以复制导出,为我的客户端应用程序创建一个,为我的服务器创建一个,但我将复制每个模块、规则、插件和其他将发展的配置!可扩展性太差了.

I can duplicate exports, creating one for my client app, and one for my server, but i will duplicate every modules, rules, plugins and other configurations that will evolves ! so bad scalibility.

我搜索了一些东西,但一无所获......我不知道如何以及在哪里,我想我可以用一个

I search for something but found nothing... I don't how and where, I thought I could do this with a

only : 'app',

但是我再也找不到了,也许这是在我的梦中xD

but I cannot find it again, maybe this was in my dreams xD

顺便说一句,如果您认为我可以升级我的 webpack.config,如果您有任何建议,请随时分享!

btw, if you think i can upgrade my webpack.config, if you have any suggestions, feel free to share !

谢谢!

推荐答案

因为您在这里处理同构设置,(看起来).您可能想要使用两个单独的 webpack 配置.

Since you are working on an isomorphic setup here, (as it looks). You would want to use two separate webpack configurations.

有些属性如 target 只能设置为一个值并适用于您的整个条目和编译集.

There are some properties like target which can only be set to one value and apply to your entire set of entries and compilation.

幸运的是,webpack 确实允许您返回一个配置对象数组!

Luckily webpack does allow you to return an array of configuration objects!

这篇关于在一个或多个条目上配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆