Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何在.webpack.js的内添加loaders配置? #852

Open
zjjjjjjjjjjd opened this issue Jan 30, 2019 · 2 comments
Open

如何在.webpack.js的内添加loaders配置? #852

zjjjjjjjjjjd opened this issue Jan 30, 2019 · 2 comments

Comments

@zjjjjjjjjjjd
Copy link

Environment(required) | 环境(必填)

  • roadhog 2.4.9(roadhog版本)
  • Nodejs 8.9.3 and Npm 5.5.1(Nodejs 和 Npm 版本)
  • Operating environment (e.g. OS name) and its version(操作系统版本): win10

What did you do? Please provide steps to re-produce your problem.(请提供复现步骤)

在.webpackrc.js中后加入类似webpack.config.js的loader配置
webpackConfig.module.rules.unshift({ test: /\.jsx?$/, loader: 'es3ify-loader', });

What do you expected?(预期的正常效果)

提供一个可配置的字段如:
rules: [{test: /\.jsx?$/, loader: 'es3ify-loader'}]

What happen?(发生了何种非正常现象)

并没有这么一个字段

Re-producible online demo (可复现的在线demo)

场景说明

知道可以使用webpack.config.js来配置loader,但是webpack.config.js不支持babel的plugins
比如在webpack.config.js内写入
webpackConfig.babel.plugins.push('transform-runtime')
会提示找不到babel下的plugins,
所以切换到.webpackrc.js来配置,结果发现loader有配置不来,该如何解决?

@codepandy
Copy link

@zjjjjjjjjjjd 求救,我新建了一个webpack.config.js,在里面配置了loader,但是提示

TypeError: customConfigFn is not a function

我的webpack.config.js代码如下

const config = {
  module: {
    rules: [
      {
        test: /\.css|less$/,
        use: [
          "style-loader",
          { loader: "css-loader", options: { importLoaders: 2 } },
          "postcss-loader",
          "less-loader",
        ],
      },
    ],
  },
};

module.exports = config;

我就想增加postcss-laoder。

@jeffrey-fu
Copy link

getUserConfig
⬇️
getConfig
⬇️
applyWebpackConfig

大家可以参考下af-webpack获取webpackConfig的过程就明白了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants