Created
May 2, 2020 17:35
-
-
Save jayu/0436ca3dc920470c9d8208f22d6614f9 to your computer and use it in GitHub Desktop.
Linaria with Gatsby without plugins
This file contains hidden or 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
module.exports = { | |
presets: [ | |
'babel-preset-gatsby', | |
[ | |
'linaria/babel', | |
{ | |
evaluate: true, | |
displayName: process.env.NODE_ENV !== 'production' | |
} | |
], | |
] | |
}; |
This file contains hidden or 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
exports.onCreateWebpackConfig = ({ actions, loaders, getConfig, stage}) => { | |
const config = getConfig() | |
config.module.rules = [ | |
...config.module.rules.filter( | |
rule => String(rule.test) !== String(/\.js?$/) | |
), | |
{ | |
...loaders.js(), | |
test: /\.js?$/, | |
options: { | |
babelrc: false, | |
configFile: false, | |
presets: [ | |
['@babel/preset-env', { useBuiltIns: 'usage' }], | |
'@babel/preset-react' | |
], | |
plugins: [ | |
'@babel/plugin-proposal-class-properties', | |
'@babel/plugin-proposal-object-rest-spread' | |
] | |
}, | |
}, | |
{ | |
test: /\.js?$/, | |
loader: 'linaria/loader', | |
options: { | |
sourceMap: stage.includes('develop'), | |
displayName: stage.includes('develop'), | |
babelOptions: { | |
presets: ['babel-preset-gatsby'], | |
}, | |
}, | |
exclude: /node_modules/ | |
}, | |
] | |
actions.replaceWebpackConfig(config) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment