这是我的webpack配置:
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var autoprefixer = require('autoprefixer');
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./playground/reactLib/playground.jsx'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
eslint: {
configFile: 'lint/.eslintrc.js'
},
resolve: {
root: path.resolve(__dirname),
alias: {
'button': 'aframe/components/buttons/Button.jsx',
}
},
module: {
preLoaders: [
{
test: /\.jsx?$/,
loader: 'eslint-loader',
include: [path.join(__dirname, 'playground'), path.join(__dirname, 'aframe')],
exclude: /node_modules/
}
],
loaders: [
{ test: /\.less$/, loader: "style!css!less",include: __dirname },
{ test: /\.css$/, loader: "style!css" },
{
test: /.jsx?$/,
loaders: ['react-hot'],
include: __dirname,
exclude: /node_modules/
},
{
test: /.jsx?$/,
loader: 'babel-loader',
include: __dirname,
exclude: /node_modules/,
query: {
plugins: ['transform-object-rest-spread'],
presets: ['es2015', 'react']
}
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file?name=static/fonts/[name].[ext]'
},
{
test: /\.png$/,
loader: 'file?name=static/[name].[ext]'
}
]
}
};当我运行webpack的时候,我得到了这个错误:
无法解析到模块的路径“按钮”
当我在不使用eslint预加载器的情况下运行这个程序时,它工作得很好。似乎在使用解析时,eslint加载程序和解析路径存在问题。有什么办法能解决这个问题吗?
发布于 2016-08-09 15:40:24
好的,答案是使用eslint-导入解析器-webpack模块,并将其添加到我的.eslintrc中。
module.exports = {
...
// These settings are needed for eslint to play well with webpack resolve
"settings": {
"import/parser": "babel-eslint",
"import/resolver": {
"webpack": { "config": "webpack.config.js" }
}
},
...
};但是,请注意以下限制:https://libraries.io/npm/eslint-import-resolver-webpack
然而,Webpack允许Node不允许在导入模块源字符串中使用许多东西,例如加载器(import‘file!/什么的’)和一些混叠方案,比如外部:在运行时将模块id映射为全局名称(允许一些模块通过脚本标记更传统地包括在内)。
https://stackoverflow.com/questions/38844405
复制相似问题