My NextJS project has the following Webpack configuration:
import path from 'path';
import glob from 'glob';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import webpack from 'webpack';
import dotenv from 'dotenv';
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import withSass from '@zeit/next-sass';
dotenv.config();
module.exports = withSass({
distDir: '.build',
webpack: (config, { dev, isServer }) => {
if (isServer) {
return config;
}
config.plugins.push(
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
);
config.optimization.minimizer.push(
new OptimizeCSSAssetsPlugin({}),
);
return config;
},
});
This allows me to just import any number of scss files in any page and have them all bundled together, minified as a single file, and served thus:
<link rel="stylesheet" href="/_next/static/css/styles.84a02761.chunk.css">
However, instead of <link>
, I'd very much prefer to have the style definitions inlined into my <head>
tag as <style></style>
. Is it possible without piling up a ton of third-party modules?
If not, is it possible to at least change the resulting <link>
's rel
to preload
from stylesheet
and also add add as="style" crossorigin
to it?