首页 > 解决方案 > 添加 Webpacker 自定义加载器会使 webpacker 行为不正确

问题描述

如果我添加一个自定义加载器,例如 haml 加载器:

// config/webpack/rules/haml.js
module.exports = {
    module: {
      rules: [
        {
          test: /\.haml$/,
          loader: 'haml-haml-loader'
        }
      ]
    },
    resolve: {
      extensions: ['.haml']
    }
  }



// config/webpack/base.js
const { webpackConfig, merge } = require('@rails/webpacker')
const hamlConfig = require('./rules/haml')

module.exports = merge(hamlConfig, webpackConfig)

一些应用程序文件停止加载。例如,我收到 Angular 错误,因为未加载相应的文件:

TypeError: Cannot read properties of undefined

只需删除此自定义加载程序即可使一切正常。当添加任何自定义加载器时,应用程序文件由于某种原因停止加载。有什么想法吗?

Webpacker 版本为 6。官方文档:https ://github.com/rails/webpacker#typescript

标签: ruby-on-railsangularwebpackruby-on-rails-5webpacker

解决方案


推荐阅读