{"action":"created","issue":{"url":"https://api.github.com/repos/m-allanson/gatsby-plugin-module-local-ident-name/issues/5","repository_url":"https://api.github.com/repos/m-allanson/gatsby-plugin-module-local-ident-name","labels_url":"https://api.github.com/repos/m-allanson/gatsby-plugin-module-local-ident-name/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/m-allanson/gatsby-plugin-module-local-ident-name/issues/5/comments","events_url":"https://api.github.com/repos/m-allanson/gatsby-plugin-module-local-ident-name/issues/5/events","html_url":"https://github.com/m-allanson/gatsby-plugin-module-local-ident-name/issues/5","id":359979522,"node_id":"MDU6SXNzdWUzNTk5Nzk1MjI=","number":5,"title":"Update for Gatsby v2","user":{"login":"m-allanson","id":381801,"node_id":"MDQ6VXNlcjM4MTgwMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/381801?v=4","gravatar_id":"","url":"https://api.github.com/users/m-allanson","html_url":"https://github.com/m-allanson","followers_url":"https://api.github.com/users/m-allanson/followers","following_url":"https://api.github.com/users/m-allanson/following{/other_user}","gists_url":"https://api.github.com/users/m-allanson/gists{/gist_id}","starred_url":"https://api.github.com/users/m-allanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-allanson/subscriptions","organizations_url":"https://api.github.com/users/m-allanson/orgs","repos_url":"https://api.github.com/users/m-allanson/repos","events_url":"https://api.github.com/users/m-allanson/events{/privacy}","received_events_url":"https://api.github.com/users/m-allanson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-13T16:52:16Z","updated_at":"2018-12-07T17:55:17Z","closed_at":null,"author_association":"OWNER","body":"I have some WIP code that _works on my machine_ ™️, in `gatsby-node.js` for my current project: \r\n\r\n```js\r\n// This should be configurable\r\nconst newIdent = `[folder]-[local]-[hash:base64:5]`;\r\n\r\n// borrowed from https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-postcss\r\nconst CSS_PATTERN = /\\.css$/;\r\nconst MODULE_CSS_PATTERN = /\\.module\\.css$/;\r\nconst isCssRules = rule =>\r\n  rule.test &&\r\n  (rule.test.toString() === CSS_PATTERN.toString() ||\r\n    rule.test.toString() === MODULE_CSS_PATTERN.toString());\r\n\r\nconst findCssRules = config =>\r\n  config.module.rules.find(\r\n    rule => Array.isArray(rule.oneOf) && rule.oneOf.every(isCssRules)\r\n  );\r\n\r\nexports.onCreateWebpackConfig = ({ stage, getConfig, actions }) => {\r\n  const config = getConfig();\r\n  const cssRules = findCssRules(config);\r\n\r\n  if (stage === `develop`) {\r\n    cssRules.oneOf.map(rule =>\r\n      rule.use.map(useItem => {\r\n        if (useItem.options && useItem.options.localIdentName) {\r\n          useItem.options.localIdentName = newIdent;\r\n        }\r\n        return newIdent;\r\n      })\r\n    );\r\n\r\n    if (cssRules) {\r\n      actions.replaceWebpackConfig(config);\r\n    }\r\n  }\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/m-allanson/gatsby-plugin-module-local-ident-name/issues/comments/445313036","html_url":"https://github.com/m-allanson/gatsby-plugin-module-local-ident-name/issues/5#issuecomment-445313036","issue_url":"https://api.github.com/repos/m-allanson/gatsby-plugin-module-local-ident-name/issues/5","id":445313036,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NTMxMzAzNg==","user":{"login":"julienben","id":8948127,"node_id":"MDQ6VXNlcjg5NDgxMjc=","avatar_url":"https://avatars2.githubusercontent.com/u/8948127?v=4","gravatar_id":"","url":"https://api.github.com/users/julienben","html_url":"https://github.com/julienben","followers_url":"https://api.github.com/users/julienben/followers","following_url":"https://api.github.com/users/julienben/following{/other_user}","gists_url":"https://api.github.com/users/julienben/gists{/gist_id}","starred_url":"https://api.github.com/users/julienben/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julienben/subscriptions","organizations_url":"https://api.github.com/users/julienben/orgs","repos_url":"https://api.github.com/users/julienben/repos","events_url":"https://api.github.com/users/julienben/events{/privacy}","received_events_url":"https://api.github.com/users/julienben/received_events","type":"User","site_admin":false},"created_at":"2018-12-07T17:55:17Z","updated_at":"2018-12-07T17:55:17Z","author_association":"NONE","body":"If anyone's having the same issue and stumbles here from Gatsby V2, this should work for .module.scss files.\r\n\r\n```js\r\nconst cssLoaderRe = /\\/css-loader\\//;\r\nconst targetFile = '.module.scss';\r\n\r\nconst processRule = rule => {\r\n  if (rule.oneOf) {\r\n    return {\r\n      ...rule,\r\n      oneOf: rule.oneOf.map(processRule),\r\n    };\r\n  }\r\n\r\n  if (!rule.test.test(targetFile)) {\r\n    return rule;\r\n  }\r\n\r\n  if (Array.isArray(rule.use)) {\r\n    return {\r\n      ...rule,\r\n      use: rule.use.map(use => {\r\n        if (!cssLoaderRe.test(use.loader)) {\r\n          return use;\r\n        }\r\n\r\n        // Adjust css-loader options\r\n        return {\r\n          ...use,\r\n          options: {\r\n            ...use.options,\r\n            localIdentName:\r\n              process.env.NODE_ENV === 'production'\r\n                ? '[hash:base64:8]'\r\n                : '[name]_[local]_[hash:base64:4]',\r\n          },\r\n        };\r\n      }),\r\n    };\r\n  }\r\n\r\n  return rule;\r\n};\r\n\r\nexports.onCreateWebpackConfig = ({ getConfig, actions }) => {\r\n  const config = getConfig();\r\n\r\n  const newConfig = {\r\n    ...config,\r\n    module: {\r\n      ...config.module,\r\n      rules: config.module.rules.map(processRule),\r\n    },\r\n  };\r\n  actions.replaceWebpackConfig(newConfig);\r\n};\r\n```"}}
{"actor":{"display_login":"julienben"}}