当我想用:
创建我的bundle.js时$ ./node_modules/.bin/webpack --config webpack.config.js
我收到以下错误
> ./dev/js/source/scripts/components/TextInput.js中的错误模块没有 发现:错误:无法解析模块 'source / scripts / components / IconButton'中 /用户/塞巴斯蒂安/文档/使用Javascript /测试/ MyApp的的/ dev / JS /源极/脚本/组件 @ ./dev/js/source/scripts/components/TextInput.js 4:18-65 > ./dev/js/source/scripts/components/TextInput.js中的错误模块没有 发现:错误:无法解析模块'source / scripts / SDK / classNames' /用户/塞巴斯蒂安/文档/使用Javascript /测试/ MyApp的的/ dev / JS /源极/脚本/组件 @ ./dev/js/source/scripts/components/TextInput.js 15:17-57
项目树如下
/Users/sebastien/Documents/Javascript/Tests/MyApp
- webpack.config.js
- dev
- js
- index.js
- source
- scripts
- components
- TextInput.js
- IconButton.js
- SDK
- classNames.js
在TextInput.js中有以下语句
import IconButton from "source/scripts/components/IconButton";
我的webpack.config.js包含以下内容
var path = require('path');
var webpack = require('webpack');
module.exports = {
devServer: {
inline: true,
contentBase: './src',
port: 8080
},
devtool: 'cheap-module-eval-source-map',
entry: './dev/js/index.js',
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
},
{
test: /\.scss/,
loader: 'style-loader!css-loader!sass-loader'
}
]
},
output: {
path: 'src',
filename: 'js/bundle.min.js'
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin()
]
};
如何配置webpack以添加路径./dev/js来搜索模块?我尝试过:
- modules: [path.resolve(__dirname, "./dev/js"), "node_modules"]
没有任何成功。你能帮忙吗?
此致
答案 0 :(得分:0)
尝试
import IconButton from "./source/scripts/components/IconButton";
看看是否有帮助。
或
import IconButton from "../source/scripts/components/IconButton";
但第一个应该可行。试一试。