Comments (5)
@jaqua
#58 is just another pattern for combining plugins. It gives additional functionality (every plugin has his own config), but it will be useful if #55 will be merged. Then will be easy to create 2 or more style files (for example vendor.css
and app.css
). And it will not resolve your problem.
Your trouble can be fixed by recalling commonsChunkConfig
with correct extensions:
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const commonsChunkConfig = require('@zeit/next-css/commons-chunk-config')
module.exports = withCSS(withSass({
webpack: (config, { isServer }) => {
if (!isServer) {
config = commonsChunkConfig(config, /\.(sass|scss|css)$/)
}
return config
}
}))
The reason of that bug is CommonChunkPlugin which is working just for one extension (withCSS pass undefined and it used /.css$/, sass pass /.(sass|scss)$/, etc). You can find it here and here
from next-plugins.
even with suggestions from @JerryCauser it doesn't work for me.
I have a project with antd (less) and my own sass stylesheets and the result is:
a) if I don't include my sass file - less get's compiled, but sass doesn't
b) if I do - less doesn't, sass does
from next-plugins.
Currently on next 5.1.0
This doesn't work for me in production, especially the SSR, and if I view the generated css files directly. I have a library used called namespace-ee/react-calendar-timeline
on github, and by including the library it also requires the css file directly.
import Timeline from 'react-calendar-timeline/lib';
I'm using this method because nextjs doesn't support some typescript/flow thing in there by default.
And I notice in production, the css included by the timeline keeps overwriting my other default scss which I included later in the page.
None of the solutions above works for me. (e.g. next-compose, commonsChunkConfig)
Edit
Nvm, turns out one of my package was outdated (@zeit/next-css was v0.1.2), after upgraded to the latest (v0.1.5) it works working SSR now.
from next-plugins.
I've come across two issues at the same time which are #21 and this one.
This is because, I use some third party libraries which required to include css (react-datepicker). And I prefer to develop component using SASS instead of styled jsx (I haven't use less)
In the end, I've create withSSSS
to combine all css, sass, scss, less and it seem to solve my case (may be this case)
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const cssLoaderConfig = require('@zeit/next-css/css-loader-config')
const commonsChunkConfig = require('@zeit/next-css/commons-chunk-config')
const MergeFilesPlugin = require('merge-files-webpack-plugin')
module.exports = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
}
const { dev, isServer } = options
const {
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
sassLoaderOptions = {},
lessLoaderOptions = {},
} = nextConfig
// Support the user providing their own instance of ExtractTextPlugin.
// If extractCSSPlugin is not defined we pass the same instance of ExtractTextPlugin to all css related modules
// So that they compile to the same file in production
let extractCSSPlugin =
nextConfig.extractCSSPlugin || options.extractCSSPlugin
//the ORIGINAL from next-css
if (!extractCSSPlugin) {
extractCSSPlugin = new ExtractTextPlugin({
filename: 'static/style.css'
})
config.plugins.push(extractCSSPlugin)
options.extractCSSPlugin = extractCSSPlugin
if (!isServer) {
config = commonsChunkConfig(config, /\.(sass|scss|less|css)$/)
}
}
//the OVERWRITTEN
//using MergeFilesPlugin to combile all css files into one file
//ref: https://github.com/zeit/next-plugins/issues/21
if (!isServer && !dev) {
// Override next-css configuration
options.extractCSSPlugin.filename = 'static/[name].css';
// Merge all CSS in one file
config.plugins.push(
new MergeFilesPlugin({
filename: 'static/style.css',
test: /\.css/,
deleteSourceFiles: true,
})
)
}
options.defaultLoaders.css = cssLoaderConfig(config, extractCSSPlugin, {
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer
})
options.defaultLoaders.sass = cssLoaderConfig(config, extractCSSPlugin, {
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer,
loaders: [
{
loader: 'sass-loader',
options: sassLoaderOptions
}
]
})
options.defaultLoaders.less = cssLoaderConfig(config, extractCSSPlugin, {
cssModules,
cssLoaderOptions,
postcssLoaderOptions,
dev,
isServer,
loaders: [
{
loader: 'less-loader',
options: lessLoaderOptions
}
]
})
config.module.rules.push({
test: /\.css$/,
use: options.defaultLoaders.css
})
config.module.rules.push({
test: /\.scss$/,
use: options.defaultLoaders.sass
},{
test: /\.sass$/,
use: options.defaultLoaders.sass
})
config.module.rules.push({
test: /\.less$/,
use: options.defaultLoaders.less
})
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
}
})
}
from next-plugins.
@supadits Have you considered creating an NPM package for withSSSS
?
from next-plugins.
Related Issues (20)
- Can not install @zeit/next-css HOT 1
- Yarn 2 - missing webpack@^4.0.0 dependency in @zeit/next-css@npm:1.0.1 HOT 1
- Cannot get CSS variables to work with npm module. HOT 2
- @zeit/next-workers: ValidationError: Invalid options object. HOT 3
- antd style does not take effect HOT 1
- with-less will disable build in css-loader HOT 2
- Absolute import with TypeScript produces errors with non ts files
- devtool option isn't working with useSourceMap HOT 4
- Unable to load fonts from SCSS using NextJS 9.5.5 HOT 1
- Source maps resolved wrongly @zeit/next-source-maps HOT 2
- @zeit/next-sass has to be updated to use node-sass v5 HOT 2
- Loading background image from SCSS doesn't work HOT 1
- Style hot reload not triggered with legacy @zeit/next-css or @zeit/next-less plugins HOT 1
- next-workers not working in Next 10? HOT 3
- Module parse failed using next-less in a typescript next js project
- CSS and SCSS with NextJS (issue while using multiple loaders: next-sass, next-css) HOT 1
- Error: PostCSS plugin tailwindcss requires PostCSS 8. HOT 1
- `localIdentName` default value for `dev` HOT 1
- Webpack plugin InjectManifest nextjs source maps "You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer"
- less config error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-plugins.