【发布时间】:2016-04-21 18:57:23
【问题描述】:
假设node_modules 中有一个名为 foo 的包,我想通过 webpack 和 babel 将一个模块导入库中,例如 foo/module...
import Foo from 'foo'; 有效
import SomeOtherModule from 'foo/module'; 失败并显示以下内容:
找不到模块:错误:无法解析模块“foo/module” /Users/x/Desktop/someproject/js
这使得 webpack 看起来像是在错误的位置而不是 node_modules 寻找文件
我的 webpack.config 如下所示:
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: ['babel-polyfill','./js/script.js'],
output: {
path: __dirname,
filename: './build/script.js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
query: {
cacheDirectory: true,
presets: ['es2015']
}
}
],
},
plugins: [
new webpack.NoErrorsPlugin()
],
stats: {
colors: true
},
devtool: 'source-map'
};
【问题讨论】:
-
请显示 foo 模块的文件和文件夹结构