Skip to content

Instantly share code, notes, and snippets.

@Dema
Created November 19, 2020 20:45
Show Gist options
  • Save Dema/e8fd40ddb1e69a0bfece5e0c292f0b05 to your computer and use it in GitHub Desktop.
Save Dema/e8fd40ddb1e69a0bfece5e0c292f0b05 to your computer and use it in GitHub Desktop.
Adds Linaria to create-react-app project that uses react-app-rewired and customize-cra
// need to add src/.linaria-cache to .gitignore. I had to move .linaria-cache inside src folder because CRA
// does not allow imports outside src folder.
// I've no idea what is this shit behind babelOptions but it works.
const addLinaria1x = () => (config) => {
addBabelPreset("linaria/babel")(config);
const babelLoader = getBabelLoader(config);
const { loader, options } = babelLoader;
const { plugins, presets } = options;
babelLoader.use = [
{ loader, options },
{
loader: require.resolve("linaria/loader"),
options: {
sourceMap: process.env.NODE_ENV !== "production",
cacheDirectory: "src/.linaria-cache",
babelOptions: {
plugins,
presets,
},
},
},
];
babelLoader.options = undefined;
babelLoader.loader = undefined;
return config;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment