如何在 webpack2 中加载 "index.js"

How to load "index.js" in webpack2

/path/to/src/index.js 中有一个文件。

在 webpack1 中,我可以使用 "import '/path/to/src'" 加载 index.js,但它在 webpack2 中不起作用,请注意 "module not found".

那么如何配置 webpack2 来自动加载 index.js 文件?

我遇到了同样的麻烦。我通过将其添加到 webpack 配置来修复它:

resolve: {extensions: ["*", ".js"]},

如果您需要扩展它或根据您的配置对其进行自定义,那么在 Webpack 的网站上有更多信息:https://webpack.js.org/configuration/resolve/

module.exports = {
    resolve: {
        extensions: [
            '/index.js', '/index.vue', '/index.json', 
            '.js', '.vue', '.json'
        ],
        alias: {
            '@': resolve('src')
        }
    }
}

我解决了这个配置的问题。但这很奇怪。