Skip to content

Instantly share code, notes, and snippets.

@Vittly
Created November 29, 2019 14:43
Show Gist options
  • Save Vittly/4244ff8b65b864674ed1739144e23386 to your computer and use it in GitHub Desktop.
Save Vittly/4244ff8b65b864674ed1739144e23386 to your computer and use it in GitHub Desktop.
SplitChunksPlugin-doesnt-play-with-postcss-imports
.Bar {
color: yellow;
}
import React from "react";
import "./Bar.scss";
export const Bar: React.FC = () => <i className="Bar">Bar</i>;
import './Foo.scss';
@import './Bar.scss';
.Foo {
background-color: green;
}
import React from "react";
import { Bar } from "./Bar";
import "./Foo.scss";
export const Foo: React.FC = () => (
<div className="Foo">
<Bar />
</div>
);
import React from 'react';
import { hydrate } from 'react-dom';
import { Foo } from './Foo';
const rootElement = document.getElementById('root');
hydrate(<Foo />, rootElement);
module.exports = {
parser: 'postcss-scss',
plugins: [
require('postcss-import')()
]
};
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const safePostCssParser = require('postcss-safe-parser');
module.exports = {
externals: {
react: 'React',
'react-dom': 'ReactDOM',
},
entry: {
cssOnly: ["./cssOnlyEntry.ts"],
hydrated: ["./hydratedEntry.tsx"]
},
output: {
path: __dirname + "/dist",
filename: '[name].js',
chunkFilename: '[name].js',
},
resolve: {
modules: [
'node_modules',
],
extensions: ['.ts', '.tsx']
},
plugins: [
new MiniCssExtractPlugin()
],
module: {
rules: [
{
test: /\.tsx?$/,
use: ["ts-loader"]
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader"
]
}
]
},
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
parser: safePostCssParser
}
})
],
splitChunks: {
cacheGroups: {
default: false,
components: {
test: /(Foo|Bar)/,
enforce: true,
chunks: "initial"
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment