Import css and sass files nextjs 7
I want be able to import in any file in my project the two types of files.
import 'styles/index.scss';
import 'styles/build/_style.css'
Its important to note im using Nextjs 7 and webpack 4 (comes with nextjs7)
In Nextjs 6 we used to use in next.config.js
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const commonsChunkConfig = (config, test = /.css$/) => {
config.plugins = config.plugins.map(plugin => {
if (
plugin.constructor.name === 'CommonsChunkPlugin' &&
plugin.minChunks != null
) {
const defaultMinChunks = plugin.minChunks;
plugin.minChunks = (module, count) => {
if (module.resource && module.resource.match(test)) {
return true;
}
return defaultMinChunks(module, count);
};
}
return plugin;
});
return config;
};
module.exports = withCSS(withSass({
webpack: (config, { isServer }) => {
config = commonsChunkConfig(config, /.(sass|scss|css)$/)
return config
}
}))
reactjs webpack-4 next.js
add a comment |
I want be able to import in any file in my project the two types of files.
import 'styles/index.scss';
import 'styles/build/_style.css'
Its important to note im using Nextjs 7 and webpack 4 (comes with nextjs7)
In Nextjs 6 we used to use in next.config.js
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const commonsChunkConfig = (config, test = /.css$/) => {
config.plugins = config.plugins.map(plugin => {
if (
plugin.constructor.name === 'CommonsChunkPlugin' &&
plugin.minChunks != null
) {
const defaultMinChunks = plugin.minChunks;
plugin.minChunks = (module, count) => {
if (module.resource && module.resource.match(test)) {
return true;
}
return defaultMinChunks(module, count);
};
}
return plugin;
});
return config;
};
module.exports = withCSS(withSass({
webpack: (config, { isServer }) => {
config = commonsChunkConfig(config, /.(sass|scss|css)$/)
return config
}
}))
reactjs webpack-4 next.js
the easiest solution is to rename_style.css
into_style.scss
and use sass loader. Why doesn't it work for you? :)
– iurii
Nov 14 '18 at 10:04
the problem is that there are some packages that has it ownstyle.css
and i just need to import it not change the package core.
– Rodrigo Chaclan
Nov 14 '18 at 19:26
ok i see. I added an example setup that work for me.
– iurii
Nov 14 '18 at 22:23
add a comment |
I want be able to import in any file in my project the two types of files.
import 'styles/index.scss';
import 'styles/build/_style.css'
Its important to note im using Nextjs 7 and webpack 4 (comes with nextjs7)
In Nextjs 6 we used to use in next.config.js
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const commonsChunkConfig = (config, test = /.css$/) => {
config.plugins = config.plugins.map(plugin => {
if (
plugin.constructor.name === 'CommonsChunkPlugin' &&
plugin.minChunks != null
) {
const defaultMinChunks = plugin.minChunks;
plugin.minChunks = (module, count) => {
if (module.resource && module.resource.match(test)) {
return true;
}
return defaultMinChunks(module, count);
};
}
return plugin;
});
return config;
};
module.exports = withCSS(withSass({
webpack: (config, { isServer }) => {
config = commonsChunkConfig(config, /.(sass|scss|css)$/)
return config
}
}))
reactjs webpack-4 next.js
I want be able to import in any file in my project the two types of files.
import 'styles/index.scss';
import 'styles/build/_style.css'
Its important to note im using Nextjs 7 and webpack 4 (comes with nextjs7)
In Nextjs 6 we used to use in next.config.js
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const commonsChunkConfig = (config, test = /.css$/) => {
config.plugins = config.plugins.map(plugin => {
if (
plugin.constructor.name === 'CommonsChunkPlugin' &&
plugin.minChunks != null
) {
const defaultMinChunks = plugin.minChunks;
plugin.minChunks = (module, count) => {
if (module.resource && module.resource.match(test)) {
return true;
}
return defaultMinChunks(module, count);
};
}
return plugin;
});
return config;
};
module.exports = withCSS(withSass({
webpack: (config, { isServer }) => {
config = commonsChunkConfig(config, /.(sass|scss|css)$/)
return config
}
}))
reactjs webpack-4 next.js
reactjs webpack-4 next.js
asked Nov 14 '18 at 2:30
Rodrigo ChaclanRodrigo Chaclan
185
185
the easiest solution is to rename_style.css
into_style.scss
and use sass loader. Why doesn't it work for you? :)
– iurii
Nov 14 '18 at 10:04
the problem is that there are some packages that has it ownstyle.css
and i just need to import it not change the package core.
– Rodrigo Chaclan
Nov 14 '18 at 19:26
ok i see. I added an example setup that work for me.
– iurii
Nov 14 '18 at 22:23
add a comment |
the easiest solution is to rename_style.css
into_style.scss
and use sass loader. Why doesn't it work for you? :)
– iurii
Nov 14 '18 at 10:04
the problem is that there are some packages that has it ownstyle.css
and i just need to import it not change the package core.
– Rodrigo Chaclan
Nov 14 '18 at 19:26
ok i see. I added an example setup that work for me.
– iurii
Nov 14 '18 at 22:23
the easiest solution is to rename
_style.css
into _style.scss
and use sass loader. Why doesn't it work for you? :)– iurii
Nov 14 '18 at 10:04
the easiest solution is to rename
_style.css
into _style.scss
and use sass loader. Why doesn't it work for you? :)– iurii
Nov 14 '18 at 10:04
the problem is that there are some packages that has it own
style.css
and i just need to import it not change the package core.– Rodrigo Chaclan
Nov 14 '18 at 19:26
the problem is that there are some packages that has it own
style.css
and i just need to import it not change the package core.– Rodrigo Chaclan
Nov 14 '18 at 19:26
ok i see. I added an example setup that work for me.
– iurii
Nov 14 '18 at 22:23
ok i see. I added an example setup that work for me.
– iurii
Nov 14 '18 at 22:23
add a comment |
1 Answer
1
active
oldest
votes
This basic example works for me with having next-sass
and next-css
side by side
/next.config.js
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
module.exports = withCSS(withSass());
/pages/index.js
import '../styles.scss';
import '../styles.css';
export default () => {
return (
<div className="example-sass">
<h1 className="example-css">Here I am</h1>
</div>
);
};
/styles.css
.example-css {
background-color: #ccc;
}
/styles.scss
$font-size: 50px;
.example-sass {
font-size: $font-size;
}
/package.json
"dependencies": {
"@zeit/next-css": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"next": "^7.0.2",
"node-sass": "^4.10.0",
"react": "^16.6.3",
"react-dom": "^16.6.3"
}
Here is what I see on the screen
Hope this helps!
PS there is some info on official GitHub repo as well
Greate! i just had to update my css/sass/next dependencys and works! Thank you
– Rodrigo Chaclan
Nov 17 '18 at 18:29
Any idea how I can deploy this to zeit-now? What should I put into now.json? Thanks
– OneIsMe
Dec 7 '18 at 17:24
I just tried and see that there is some issue with deploying next/css and next/sass to now v2. Here is an issue I face as well github.com/zeit/next.js/issues/5750#issuecomment-443562606
– iurii
Dec 7 '18 at 17:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292355%2fimport-css-and-sass-files-nextjs-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This basic example works for me with having next-sass
and next-css
side by side
/next.config.js
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
module.exports = withCSS(withSass());
/pages/index.js
import '../styles.scss';
import '../styles.css';
export default () => {
return (
<div className="example-sass">
<h1 className="example-css">Here I am</h1>
</div>
);
};
/styles.css
.example-css {
background-color: #ccc;
}
/styles.scss
$font-size: 50px;
.example-sass {
font-size: $font-size;
}
/package.json
"dependencies": {
"@zeit/next-css": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"next": "^7.0.2",
"node-sass": "^4.10.0",
"react": "^16.6.3",
"react-dom": "^16.6.3"
}
Here is what I see on the screen
Hope this helps!
PS there is some info on official GitHub repo as well
Greate! i just had to update my css/sass/next dependencys and works! Thank you
– Rodrigo Chaclan
Nov 17 '18 at 18:29
Any idea how I can deploy this to zeit-now? What should I put into now.json? Thanks
– OneIsMe
Dec 7 '18 at 17:24
I just tried and see that there is some issue with deploying next/css and next/sass to now v2. Here is an issue I face as well github.com/zeit/next.js/issues/5750#issuecomment-443562606
– iurii
Dec 7 '18 at 17:58
add a comment |
This basic example works for me with having next-sass
and next-css
side by side
/next.config.js
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
module.exports = withCSS(withSass());
/pages/index.js
import '../styles.scss';
import '../styles.css';
export default () => {
return (
<div className="example-sass">
<h1 className="example-css">Here I am</h1>
</div>
);
};
/styles.css
.example-css {
background-color: #ccc;
}
/styles.scss
$font-size: 50px;
.example-sass {
font-size: $font-size;
}
/package.json
"dependencies": {
"@zeit/next-css": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"next": "^7.0.2",
"node-sass": "^4.10.0",
"react": "^16.6.3",
"react-dom": "^16.6.3"
}
Here is what I see on the screen
Hope this helps!
PS there is some info on official GitHub repo as well
Greate! i just had to update my css/sass/next dependencys and works! Thank you
– Rodrigo Chaclan
Nov 17 '18 at 18:29
Any idea how I can deploy this to zeit-now? What should I put into now.json? Thanks
– OneIsMe
Dec 7 '18 at 17:24
I just tried and see that there is some issue with deploying next/css and next/sass to now v2. Here is an issue I face as well github.com/zeit/next.js/issues/5750#issuecomment-443562606
– iurii
Dec 7 '18 at 17:58
add a comment |
This basic example works for me with having next-sass
and next-css
side by side
/next.config.js
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
module.exports = withCSS(withSass());
/pages/index.js
import '../styles.scss';
import '../styles.css';
export default () => {
return (
<div className="example-sass">
<h1 className="example-css">Here I am</h1>
</div>
);
};
/styles.css
.example-css {
background-color: #ccc;
}
/styles.scss
$font-size: 50px;
.example-sass {
font-size: $font-size;
}
/package.json
"dependencies": {
"@zeit/next-css": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"next": "^7.0.2",
"node-sass": "^4.10.0",
"react": "^16.6.3",
"react-dom": "^16.6.3"
}
Here is what I see on the screen
Hope this helps!
PS there is some info on official GitHub repo as well
This basic example works for me with having next-sass
and next-css
side by side
/next.config.js
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
module.exports = withCSS(withSass());
/pages/index.js
import '../styles.scss';
import '../styles.css';
export default () => {
return (
<div className="example-sass">
<h1 className="example-css">Here I am</h1>
</div>
);
};
/styles.css
.example-css {
background-color: #ccc;
}
/styles.scss
$font-size: 50px;
.example-sass {
font-size: $font-size;
}
/package.json
"dependencies": {
"@zeit/next-css": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"next": "^7.0.2",
"node-sass": "^4.10.0",
"react": "^16.6.3",
"react-dom": "^16.6.3"
}
Here is what I see on the screen
Hope this helps!
PS there is some info on official GitHub repo as well
answered Nov 14 '18 at 22:22
iuriiiurii
2,67311321
2,67311321
Greate! i just had to update my css/sass/next dependencys and works! Thank you
– Rodrigo Chaclan
Nov 17 '18 at 18:29
Any idea how I can deploy this to zeit-now? What should I put into now.json? Thanks
– OneIsMe
Dec 7 '18 at 17:24
I just tried and see that there is some issue with deploying next/css and next/sass to now v2. Here is an issue I face as well github.com/zeit/next.js/issues/5750#issuecomment-443562606
– iurii
Dec 7 '18 at 17:58
add a comment |
Greate! i just had to update my css/sass/next dependencys and works! Thank you
– Rodrigo Chaclan
Nov 17 '18 at 18:29
Any idea how I can deploy this to zeit-now? What should I put into now.json? Thanks
– OneIsMe
Dec 7 '18 at 17:24
I just tried and see that there is some issue with deploying next/css and next/sass to now v2. Here is an issue I face as well github.com/zeit/next.js/issues/5750#issuecomment-443562606
– iurii
Dec 7 '18 at 17:58
Greate! i just had to update my css/sass/next dependencys and works! Thank you
– Rodrigo Chaclan
Nov 17 '18 at 18:29
Greate! i just had to update my css/sass/next dependencys and works! Thank you
– Rodrigo Chaclan
Nov 17 '18 at 18:29
Any idea how I can deploy this to zeit-now? What should I put into now.json? Thanks
– OneIsMe
Dec 7 '18 at 17:24
Any idea how I can deploy this to zeit-now? What should I put into now.json? Thanks
– OneIsMe
Dec 7 '18 at 17:24
I just tried and see that there is some issue with deploying next/css and next/sass to now v2. Here is an issue I face as well github.com/zeit/next.js/issues/5750#issuecomment-443562606
– iurii
Dec 7 '18 at 17:58
I just tried and see that there is some issue with deploying next/css and next/sass to now v2. Here is an issue I face as well github.com/zeit/next.js/issues/5750#issuecomment-443562606
– iurii
Dec 7 '18 at 17:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292355%2fimport-css-and-sass-files-nextjs-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
the easiest solution is to rename
_style.css
into_style.scss
and use sass loader. Why doesn't it work for you? :)– iurii
Nov 14 '18 at 10:04
the problem is that there are some packages that has it own
style.css
and i just need to import it not change the package core.– Rodrigo Chaclan
Nov 14 '18 at 19:26
ok i see. I added an example setup that work for me.
– iurii
Nov 14 '18 at 22:23