How to import images #1739
-
Hi! I'm trying to convert my create-react-app app to razzle and have almost everything working except imports of images, e.g. module.exports = {
modifyWebpackConfig(opts) {
const config = Object.assign({}, opts.webpackConfig);
config.module.rules.push({
test: /\.(woff(2)?|ttf|eot|otf)(\?v=\d+\.\d+\.\d+)?$/,
loader: "url-loader?limit=10000",
});
config.module.rules.push({
test: /\.(gif|png|jif|pdf|jpg|bmp|jpeg)$/,
loader: "url-loader?limit=10000",
});
return config;
},
}; However this seems to have no effect. Are there any docs / examples I could look at to figure out how to get this to work? And would it be worth adding an example to the examples folder of the repo? Extra information: I'm using Typescript with a module alias, however neither imports using the alias nor relative imports of images are working. In case needed, {
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"baseUrl": "src",
"paths": {
"@goodgym/*": ["*"]
}
},
"include": ["src"]
} and {
"presets": ["razzle/babel", "@emotion/babel-preset-css-prop"],
"plugins": ["babel-plugin-lodash"]
} Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Sigh. Immediately after posting this discussion I figure out it's actually a Typescript issue. Fixed by creating declare module "*.jpg";
declare module "*.png"; and updating "include": ["src", "src/global.d.ts"] |
Beta Was this translation helpful? Give feedback.
Sigh. Immediately after posting this discussion I figure out it's actually a Typescript issue. Fixed by creating
src/global.d.ts
:and updating
tsconfig.json
to include: