Created
November 19, 2020 20:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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