Last active
July 12, 2018 01:44
-
-
Save MoOx/12ac2bee8d876a5c1fe1593e4815895d to your computer and use it in GitHub Desktop.
flow config webpack adjustements to avoid the "Required module not found" for png, css, svg etcc
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
# ... | |
[options] | |
# webpack loaders | |
module.name_mapper='.*\.css$' -> '<PROJECT_ROOT>/flow/stub/css-modules.js' | |
module.name_mapper='.*\.\(svg\|png\|jpg\|gif\)$' -> '<PROJECT_ROOT>/flow/stub/url-loader.js' |
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
// @flow | |
type CSSModule = { [key: string]: string } | |
const emptyCSSModule: CSSModule = {} | |
export default emptyCSSModule |
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
// @flow | |
const s: string = "" | |
export default s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 on directly declaring the
export default
type. Nice approach.Also, 👍 on not using the
module.name_mapper.extension
shorthand, as @jvalente instructed. I was unable to configure multiplemodule.name_mapper
directives and have them work well together when using the.extension
version and couldn’t figure out why. Specifically, I needed to be able to use the css stub for module names matching'.*\.css$'
, but overriding that if the module name starts with!raw!
to use the file stub (export string) version. Here’s what worked:.flowconfig
However, when I had the same config, just with
module.name_mapper='.*\.css$' -> '<PROJECT_ROOT>/flow/stub/css-modules.js
replaced withmodule.name_mapper.extension='css' -> '<PROJECT_ROOT>/flow/stub/css-modules.js'
, that name_mapper overrides the!raw!
name_mapper and makes flow think thatimport Raw from '!raw!./style.css
will import an object.