首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webpack弹性装载机解析路径时的问题

Webpack弹性装载机解析路径时的问题
EN

Stack Overflow用户
提问于 2016-08-09 07:16:21
回答 1查看 3.3K关注 0票数 1

这是我的webpack配置:

代码语言:javascript
复制
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加载程序和解析路径存在问题。有什么办法能解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2016-08-09 15:40:24

好的,答案是使用eslint-导入解析器-webpack模块,并将其添加到我的.eslintrc中。

代码语言:javascript
复制
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映射为全局名称(允许一些模块通过脚本标记更传统地包括在内)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38844405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档