如何在子目录中运行wepback项目?

时间:2017-01-01 06:00:13

标签: javascript node.js webpack config resolve

我有一个带有此文件的子目录subdir

// subdir/local.js
document.body.textContent = 'hello from subdir/local.js'

和本地webpack.config.js

// subdir/webpack.config.js
const { 
  createConfig, 
  entryPoint, 
  setOutput } = require('@webpack-blocks/webpack')

const devServer = require('@webpack-blocks/dev-server')

module.exports = createConfig([
  entryPoint('.'),
  setOutput('./bundle.js'),
  devServer(),
])

相同的配置在根目录中有效。但是,在本地运行

webpack local.js

导致错误:

ERROR in multi main
Module not found: Error: Cannot resolve 'file' or 'directory' . in /Users/dmitrizaitsev/Dropbox/Sandbox/webpack-blocks-test/subdir
 @ multi main

如何修复该错误并使用子目录中的项目运行webpack?

1 个答案:

答案 0 :(得分:0)

虽然webpack使用module resolution的扩展版节点require,但默认情况下不会解析local.js。我认为如果你要将local.js重命名为index.js,那就可以了。否则,您只需将入口点设置为./index.js./index即可。