本文介绍了WebPack 2:迁移 preLoaders 和 postLoader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 webpack@2.1.0-beta.27.之前,我使用的是 webpack@2.1.0-beta.22.在我的配置文件中,我使用了 preLoaderspostLoaders:

I've installed webpack@2.1.0-beta.27. Before, I was using webpack@2.1.0-beta.22. On my configuration file I was using preLoaders and postLoaders:

preLoaders: [
    {
      test: /\.ts$/,
      loader: 'string-replace-loader',
      query: {
        search: '(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import\\((.+)\\)',
        replace: '$1.import($3).then(mod => (mod.__esModule && mod.default) ? mod.default : mod)',
        flags: 'g'
      },
      include: [helpers.root('src')]
    },

  ],
  loaders: [...],
  postLoaders: [
    {
      test: /\.js$/,
      loader: 'string-replace-loader',
      query: {
        search: 'var sourceMappingUrl = extractSourceMappingUrl\\(cssText\\);',
        replace: 'var sourceMappingUrl = "";',
        flags: 'g'
      }
    }
  ]

在 Internet 上查看后,我无法弄清楚如何迁移此 preLoaderspostLoaders.

I'm not able to figure out once I've took a look on internet how to migrate this preLoaders and postLoaders.

我应该将它们放在 loaders 中吗?仅此而已?

Should I put them inside loaders? Only that?

推荐答案

从 v2.1-beta.23 开始,loaders 部分被重命名为 rules,并且 pre/postLoaders 现在在每个规则下定义了 enforce 属性.

From v2.1-beta.23 the loaders section is renamed to rules and pre/postLoaders is now defined under each rule with the enforce property.

我在 这个话题

更多信息也可以在发行说明 在 github 上

More info can also be found in the release notes on github

发行说明还在 angular cli 中提到了迁移示例回购

The release notes also mentions a migration example in the angular cli repo

另一个技巧是查看 json schema验证提示的配置.

Another tip is to look at the json schema that validates the config for hints.

这篇关于WebPack 2:迁移 preLoaders 和 postLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 00:22