Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for configuring the exclude rule of the webpack config #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,31 @@ module.exports = withLinaria({
},
});
```
### Transpiling Linaria files from node_modules
By default this package will ignore all of node_modules by default.

If you have a package inside of node_modules with Linaria files that you would like to transpile, you need to add the package to the rules array of the Linaria config

Keep in mind that this overrides Linaria's default rules, so you will want to make sure you add
```js
// next.config.js
const withLinaria = require('next-linaria');
module.exports = withLinaria({
linaria: {
rules: [
{
action: require('@linaria/shaker').default,
},
{
test: /node_modules[\/\\](?!\@example\\package)/,
action: 'ignore',
},
],
/* other linaria options here */
},
});
```
This can be used in combination with https://github.com/martpie/next-transpile-modules to transpile the rest of the package if necessary
## License

The MIT License (MIT)
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,24 @@ function traverse(rules) {
}
}

function getLinariaIgnore(linariaConfig) {
if (linariaConfig && linariaConfig.rules) {
const ignoreRule = linariaConfig.rules.find(rule =>
rule.action && rule.action === 'ignore' && rule.test
);
return ignoreRule && ignoreRule.test
}
return null;
}

module.exports = (nextConfig = {}) => {
return {
...nextConfig,
webpack(config, options) {
traverse(config.module.rules);
config.module.rules.push({
test: /\.(tsx|ts|js|mjs|jsx)$/,
exclude: /node_modules/,
exclude: getLinariaIgnore(nextConfig.linaria) || /node_modules/,
use: [
{
loader: require.resolve('@linaria/webpack-loader'),
Expand Down