How to use several next.js plugins (typescript and stylus)

落花浮王杯 提交于 2019-12-11 02:25:19

问题


I try to build next.js project with typescript and stylus using next-compose-plugins.

My next.config.js:

const withPlugins = require('next-compose-plugins')
const withTypescript = require('@zeit/next-typescript')
const withStylus = require('@zeit/next-stylus')

module.exports = withPlugins([

  [withTypescript, {
    webpack(config, options) {
      config.node = {
        fs: 'empty',
      }

      return config
    },
    typescriptLoaderOptions: {
      transpileOnly: false,
    }
  }],

  [withStylus, {
    cssModules: true,
  }],

])

In my button.tsx I'm importing stylus file:

import styles from './button.styl'
console.log(styles) // undefined

button.styl contains class names I'd like to use in my components but instead getting undefined.

I've added declare module '*.styl' to my externals.d.ts and included it in include section of tsconfig.json

What am I doing wrong?

UPD: getting same issue for @zeit/next-css.


回答1:


@zeit/next-typescript 1.0.0 is released 3 days ago, and raise error with typescriptLoaderOptions:

Error: `typescriptLoaderOptions` in next.config.js is no longer supported. https://err.sh/next-plugins/typescript-loader-options
    at module.exports (/Users/set0gut1/tmp/stackoverflow/nextjs/node_modules/@zeit/next-typescript/index.js:15:11)

With this version, I could import stylus file.

  • next.config.js: delete typescriptLoaderOptions from yours.
  • I do not make externals.d.ts
  • index.tsx:

import styles from './button.styl'
console.log(styles) // { 'button-class-name': '_1U60cMSmedjISleJqYp7tU' }

export default () => {
    return <div>test</div>
}


来源:https://stackoverflow.com/questions/50294005/how-to-use-several-next-js-plugins-typescript-and-stylus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!