Webpack无法解析html-loader

贾巴尔雷罗斯

我正在将使用requirejs的项目转换为webpack,并遇到“ html-loader”加载器的问题。

package.json:

"html-loader": "^0.3.0",
"webpack": "^1.11.0",
"webpack-dev-server": "^1.10.1"

app / js / webpack.config.js:

  // folder structure:
  // root
  //   app/js
  //   bower_components/
  //   dist/
  //   node_modules/

  entry: './app/js/main.js',
  output: {
    path: 'dist/js/',
    filename: 'bundle.js',
  },
  module: {
    loaders: [
      // Note, via requirejs's "text" plugin, I included templates
      // like this: var tpl = require('text!sample.html');
      // For webpack, I went through the codebase and cleaned up
      // every instance of "text!".
      {test: /\.html$/, loader: 'html'}
    ]
  },
  resolve: {
    root: ['app/js', 'bower_components'],
    alias: {
      ...
    }
  },
  plugins: [
    new webpack.ResolverPlugin(
      new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(
        'bower.json', ['main']
      )
    )
  ]

当我运行webpack时--webpack --config app/js/webpack.config.js我收到以下错误消息:

app / js / some / file.js中的
错误找不到模块:错误:无法解析app / js / some / file.js中的模块'html'

我尝试了以下方法,但没有用:

  resolveLoader: {
    root: [path.join(__dirname, 'node_modules')],
  },

还尝试将“ webpack.config.js”移至项目根目录。那也没有帮助。

而且,甚至尝试使用“原始加载器”加载器,这也会导致相同的“无法解析模块“原始””错误。

任何帮助,将不胜感激。谢谢。

贾巴尔雷罗斯

完全放弃了更新此球。

1)我应该一直在使用text-loader,这使我每个都可以留在原处require('text!some/template.html');

2)我的根路径不是绝对的根据手册,“它必须是绝对路径!请勿传递./app/modules之类的东西。”

3)如果您require看起来像require('text!some/file.html'),那么您就完成了。在webpack.config.js中定义加载器是多余的。如果这样做,您的模板最终将看起来像module.exports="module.exports=\"...\""

更新的配置:

entry: './app/js/main.js',
output: {
    path: 'dist/js/',
    filename: 'bundle.js',
},
module: {
    loaders: [/*nothing*/]
},
resolve: {
    root: [
        path.resolve('app/js'), 
        path.resolve('bower_components')
    ],
    alias: {
        ...
    }
},
plugins: [
    new webpack.ResolverPlugin(
        new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(
            'bower.json', ['main']
        )
    )
]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:无法解析模块“ babel-loader”

Webpack && stylus-loader错误地解析了URL路径

即使使用babel-loader,模块解析也无法通过webpack进行响应

webpack(使用sass-loader)-scss文件@import无法识别解析别名

Webpack sass loader无法识别全局变量文件

Webpack babel-loader无法解析箭头功能

Webpack [url / file-loader]无法解析URL的相对路径

具有vue-loader和sass-loader的Webpack无法导入.scss文件

react-hot-loader和webpack无法正常工作

带有pug-loader的html-webpack-plugin无法选择

没有NO loader的webpack阻止我使用高级JavaScript语法,无法在本机传播语法上解析错误

Webpack worker-loader无法编译Typescript worker

Webpack为什么无法解析“ babel-loader”?

ts-loader / css-loader无法导入/解析文件

Webpack 4中的babel loader无法摇树

为什么vue-loader&webpack-4无法正常工作?

无法解析'ngx-bootstrap / component-loader / component-loader.factory'

无法解析模块“ css-loader”

sass-loader无法解析@use规则

Zend / Loader无法打开流

Webpack bootstrap.css npm模块无法使用ExtractTextLoader + css_loader解析

无法安装postcss-loader

Webpack css-loader:“未找到模块:错误:无法解析 'main.css' in ...”

尽管已经安装,但无法解析模块 style-loader!css-loader

sass-loader 无法解析@import url

什么 webpack loader 可以解析 html 文件中的 <svg> 元素

无法解析 'css-loader' - Webpack 入门错误

带有 css-loader 的 webpack - 解析错误:';' 预期的

Django Webpack Loader:“资产”KeyError?