覆盖 Webpack 4 入口点 [英] Overriding Webpack 4 Entry Point

查看:30
本文介绍了覆盖 Webpack 4 入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的项目目录:

   -node_modules
   -src
       -client
          -js
          -styles
          -views
          -index.js
          -webpack.config.js
       -server
   -.babelrc
   -package
   -package-lock
   -README.md
   -webpack.dev
   -webpack.prod

这是我的webpack.config.js

const path = require('path')
const webpack = require('webpack')

module.exports = {
    mode: 'none',
    //entry: path.resolve(__dirname) + './src/client/index.js',

    module: {
        rules: [
            {
                test: '/\.js$./',
                exclude: /node_modules/,
                loader: "babel-loader"
            }
        ]
    }
}

我想覆盖 webpack.config.js 中的默认入口点以指向同一级别的 index.js 文件.

I want to override the default entry point inside webpack.config.js to point to the index.js file in the same level.

默认情况下,如果我在 src 目录中有 index.js 文件,而不指定入口点,它会按预期工作.

By default, if I have the index.js file inside the src directory, without specifying the entry point, it works as expected.

我尝试过像这样更改入口点:

I have tried changing the entry points like this:

入口:path.resolve(__dirname, './src/client/index.js'),

入口:path.resolve(__dirname, 'src') + 'client/index.js',

入口:path.resolve(__dirname, './src/index.js'),

入口:path.resolve(__dirname) + '/src/client/index.js',

入口:path.resolve(__dirname) + './src/client/index.js'

我使用的是 Windows 10 操作系统.

I'm using a windows 10 Operating System.

推荐答案

module.exports = {
  entry: './index.js'
};

参考:https://webpack.js.org/concepts/entry-points/

或者,您也可以使用

module.exports = {
  entry: require.resolve('./index')
};

参考:https://nodejs.org/api/modules.html#modules_require_resolve_request_options

这篇关于覆盖 Webpack 4 入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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