/** * Copyright 2020 Google Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // This tweak allows Webpack to completely dissolve intermediary className mappings. // The hashed/prefixed versions of imported classNames (style.foo) get inlined where they are used. // Example output improvement: https://gist.github.com/64b04c7d8fff564e3047226493597cc8 module.exports = function(code) { return code.replace(/export\s+default\s*(\{[^}]+\});?/, (s, json) => { try { const obj = JSON.parse(json); let out = ''; for (let key in obj) { // generated CSS classes don't contain characters that require escapement let val = obj[key]; out += `export const ${key} = "${val}";`; } return out; } catch (e) { return s; } }); };