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

配置完chainWebpack后不生效 #2577

Closed
fengxinming opened this issue Jun 11, 2019 · 10 comments
Closed

配置完chainWebpack后不生效 #2577

fengxinming opened this issue Jun 11, 2019 · 10 comments

Comments

@fengxinming
Copy link
Contributor

fengxinming commented Jun 11, 2019

What happens?

在.umirc.local.js文件中配置chainWebpack之后,所添加的配置未生效。

Mini Showcase Repository(REQUIRED)

export default {
  urlLoaderExcludes: [
    /\.styl$/,
  ],
  chainWebpack(config) {
    let { rules } = config.module.toConfig();
    console.log('-----', rules[rules.length - 1]);
    config.module
      .rule('styl')
      .test(/\.styl$/)
      // .oneOf('normal')
      .exclude
      .add(/node_modules/)
      .end()
      .use('stylus')
      .loader('stylus-loader');

    rules = config.module.toConfig().rules;
    console.log('======', JSON.stringify(rules[rules.length - 1]));
  }
}

How To Reproduce

Steps to reproduce the behavior:

  1. 在.umirc.js文件中添加stylus支持,并在使用npm或者yarn安装完模块stylus和stylus-loader。
  2. 查看控制台发现新加的loader未被解析,对比前后输出的配置json字符串可确认。
  3. Module parse failed: Unexpected token (1:0)
    You may need an appropriate loader to handle this file type.

Expected behavior

  1. 正常解析stylus文件

Context

  • Umi Version: 2.7.3
  • Node Version: v8.16.0
  • Platform: macOS 10.14.5
@sorrycc
Copy link
Member

sorrycc commented Jun 11, 2019

参考 #1421 (comment)

@sorrycc sorrycc closed this as completed Jun 11, 2019
@fengxinming
Copy link
Contributor Author

@sorrycc 不要连看都不看就关掉问题好吧,就是按照那种方式配置

@sorrycc
Copy link
Member

sorrycc commented Jun 12, 2019

给复现仓库,我看下。

@sorrycc sorrycc reopened this Jun 12, 2019
@fengxinming
Copy link
Contributor Author

@sorrycc https://github.com/fengxinming/umi-admin
进入app目录
运行 npm run dev

就用umi脚手架生成一个普通demo即可

@sorrycc
Copy link
Member

sorrycc commented Jun 12, 2019

看了下,现在不支持 stylus 的自定义配置,不是额外加一个 stylus-loader 就可以,得和 css-loader、style-loader、mini-css-extract-plugin 配合着用才可以。

建议用 less 或 sass,或者自己研究下如何实现 styl,也可以给 umi 提 PR 做。

@sorrycc sorrycc closed this as completed Jun 12, 2019
@sorrycc
Copy link
Member

sorrycc commented Jun 12, 2019

issue 关了,需要这个功能的话直接提 PR 解决。

@fengxinming
Copy link
Contributor Author

@sorrycc 我之前的项目用了stylus,里面加了一些全局高级特性,less和sass都加不了,暂时不考虑less或者sass,你能不能确认webpack-chain有没有问题,或者能不能在.umirc.js里面配置非chain的webpack配置,因为从打印上看,貌似连stylus-loader都没有被加载。

@crownclownwl
Copy link

我也遇到这个问题了,我配置了

@crownclownwl
Copy link

我在 .umirc.ts 里配置了
ts config.resolve.alias.set('idsUiThemes', 'node_modules/ids-ui-themes');
但是还是不好使,在页面中引用这个 @import '~idsUiThemes/dist/index.less'; 就说找不到文件

@neroneroffy
Copy link

neroneroffy commented Aug 6, 2020

我写了个自定义loader,按照这种方式配置,可以执行 https://blog.csdn.net/qq_37728271/article/details/100519531 。但是在某次修改了一个传参后,就进不去这个loader了。再改回原样也不行。删掉项目重新来一遍,也不行。。。

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

4 participants