admin管理员组文章数量:1296259
I need to configure next.config.js file in order to use in the same time two different loaders. This is the first:
const withSass = require('@zeit/next-sass');
module.exports = withSass({
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]",
}
})
And this is the second:
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
module.exports = withCSS(withSass({
webpack (config, options) {
config.module.rules.push({
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000
}
}
})
return config
}
}))
Individually they work great! But I'm not able to bine them in a single rule so that both can work together.
Thanks for your help!!
I need to configure next.config.js file in order to use in the same time two different loaders. This is the first:
const withSass = require('@zeit/next-sass');
module.exports = withSass({
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]",
}
})
And this is the second:
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
module.exports = withCSS(withSass({
webpack (config, options) {
config.module.rules.push({
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000
}
}
})
return config
}
}))
Individually they work great! But I'm not able to bine them in a single rule so that both can work together.
Thanks for your help!!
Share Improve this question edited Feb 4, 2019 at 8:58 Reynolds asked Feb 2, 2019 at 18:29 ReynoldsReynolds 1811 gold badge1 silver badge8 bronze badges 1- check this github./zeit/next-plugins/issues/241#issuement-411845052 – evgeni fotia Commented Feb 4, 2019 at 18:37
1 Answer
Reset to default 6You should use next-pose-plugins. Here is a link below for additional reference.
How can I bine multiple loaders (CSS, LESS, ttf, etc) in NextJS config file?
But the code below should solve your issue:
Install
yarn add --dev @zeit/next-css
yarn add --dev @zeit/next-sass file-loader url-loader
Update your next.config.js file
const withPlugins = require('next-pose-plugins');
const sass = require("@zeit/next-sass")
const css = require("@zeit/next-css")
const nextConfig = {
webpack: function (config) {
config.module.rules.push({
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]'
}
}
})
return config
}
}
module.exports = withPlugins([
[css],
[sass, {
cssModules: true
}]
], nextConfig);
Note: You should now be able to import scss modules like this:
import styles from 'your-file-name.module.scss'
Note: Watch out for vendors libs that are not formatted properly in that case you should import as follows:
import "slick-carousel/slick/slick-theme.css";
import "slick-carousel/slick/slick.css";
本文标签: javascriptReactNextjs configuration with cssModules and urlloaderStack Overflow
版权声明:本文标题:javascript - React - Next.js configuration with cssModules and url-loader - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741630574a2389338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论