({
isServer,
}: {
isServer: boolean;
})
| 53 | // TODO this historical code is quite messy |
| 54 | // We should try to get rid of it and move to assets pipeline |
| 55 | function createFileLoaderUtils({ |
| 56 | isServer, |
| 57 | }: { |
| 58 | isServer: boolean; |
| 59 | }): FileLoaderUtils { |
| 60 | // Files/images < urlLoaderLimit will be inlined as base64 strings directly in |
| 61 | // the html |
| 62 | const urlLoaderLimit = WEBPACK_URL_LOADER_LIMIT; |
| 63 | |
| 64 | const fileLoaderFileName = (folder: AssetFolder) => |
| 65 | path.posix.join( |
| 66 | OUTPUT_STATIC_ASSETS_DIR_NAME, |
| 67 | folder, |
| 68 | '[name]-[contenthash].[ext]', |
| 69 | ); |
| 70 | |
| 71 | const loaders: FileLoaderUtils['loaders'] = { |
| 72 | file: (options: {folder: AssetFolder}) => ({ |
| 73 | loader: require.resolve(`file-loader`), |
| 74 | options: { |
| 75 | name: fileLoaderFileName(options.folder), |
| 76 | emitFile: !isServer, |
| 77 | }, |
| 78 | }), |
| 79 | url: (options: {folder: AssetFolder}) => ({ |
| 80 | loader: require.resolve('url-loader'), |
| 81 | options: { |
| 82 | limit: urlLoaderLimit, |
| 83 | name: fileLoaderFileName(options.folder), |
| 84 | fallback: require.resolve('file-loader'), |
| 85 | emitFile: !isServer, |
| 86 | }, |
| 87 | }), |
| 88 | |
| 89 | // TODO avoid conflicts with the ideal-image plugin |
| 90 | // TODO this may require a little breaking change for ideal-image users? |
| 91 | // Maybe with the ideal image plugin, all md images should be "ideal"? |
| 92 | // This is used to force url-loader+file-loader on markdown images |
| 93 | // https://webpack.js.org/concepts/loaders/#inline |
| 94 | inlineMarkdownImageFileLoader: `!${escapePath( |
| 95 | require.resolve('url-loader'), |
| 96 | )}?limit=${urlLoaderLimit}&name=${fileLoaderFileName( |
| 97 | 'images', |
| 98 | )}&fallback=${escapePath(require.resolve('file-loader'))}${ |
| 99 | isServer ? `&emitFile=false` : '' |
| 100 | }!`, |
| 101 | inlineMarkdownAssetImageFileLoader: `!${escapePath( |
| 102 | require.resolve('file-loader'), |
| 103 | )}?name=${fileLoaderFileName('images')}${ |
| 104 | isServer ? `&emitFile=false` : '' |
| 105 | }!`, |
| 106 | inlineMarkdownLinkFileLoader: `!${escapePath( |
| 107 | require.resolve('file-loader'), |
| 108 | )}?name=${fileLoaderFileName('files')}${ |
| 109 | isServer ? `&emitFile=false` : '' |
| 110 | }!`, |
| 111 | }; |
| 112 |
no test coverage detected
searching dependent graphs…