webpack-contrib/file-loader là một trong những repo tập trung giao diện mà TopGit theo dõi, hiện có 1.8k sao, viết chủ yếu bằng JavaScript. File Loader
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
And run webpack via your preferred method. This will emit file.png as a file
in the output directory (with the specified naming convention, if options are
specified to do so) and returns the public URI of the file.
ℹ️ By default the filename of the resulting file is the hash of the file's contents with the original extension of the required resource.
Specifies a custom filename template for the target file(s) using the query
parameter name. For example, to emit a file from your context directory into
the output directory retaining the full directory structure, you might use:
module.exports = {
module: {
rules: [
{
test: /\.(png|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
publicPath: (url, resourcePath, context) => {
// `resourcePath` is original absolute path to asset
// `context` is directory where stored asset (`rootContext`) or `context` option
// To get relative path you can use
// const relativePath = path.relative(context, resourcePath);
if (/my-custom-image\.png/.test(resourcePath)) {
return `other_public_path/${url}`;
}
if (/images/.test(context)) {
return `image_output_path/${url}`;
}
return `public_path/${url}`;
},
},
},
],
},
};
postTransformPublicPath
Type: Function
Default: undefined
Specifies a custom function to post-process the generated public path. This can be used to prepend or append dynamic global variables that are only available at runtime, like __webpack_public_path__. This would not be possible with just publicPath, since it stringifies the values.
If true, emits a file (writes a file to the filesystem). If false, the loader
will return a public URI but will not emit the file. It is often useful to
disable this option for server-side packages.
Specifies a Regular Expression to one or many parts of the target file path.
The capture groups can be reused in the name property using [N]
placeholder.
ℹ️ If [0] is used, it will be replaced by the entire tested string, whereas [1] will contain the first capturing parenthesis of your regex and so on...
esModule
Type: Boolean
Default: true
By default, file-loader generates JS modules that use the ES modules syntax.
There are some cases in which using ES modules is beneficial, like in the case of module concatenation and tree shaking.
# result
https://cdn.example.com/directory/image.png?width=300&height=300
Dynamic public path depending on environment variable at run time
An application might want to configure different CDN hosts depending on an environment variable that is only available when running the application. This can be an advantage, as only one build of the application is necessary, which behaves differently depending on environment variables of the deployment environment. Since file-loader is applied when compiling the application, and not when running it, the environment variable cannot be used in the file-loader configuration. A way around this is setting the __webpack_public_path__ to the desired CDN host depending on the environment variable at the entrypoint of the application. The option postTransformPublicPath can be used to configure a custom path depending on a variable like __webpack_public_path__.
main.js
const assetPrefixForNamespace = (namespace) => {
switch (namespace) {
case 'prod':
return 'https://cache.myserver.net/web';
case 'uat':
return 'https://cache-uat.myserver.net/web';
case 'st':
return 'https://cache-st.myserver.net/web';
case 'dev':
return 'https://cache-dev.myserver.net/web';
default:
return '';
}
};
const namespace = process.env.NAMESPACE;
__webpack_public_path__ = `${assetPrefixForNamespace(namespace)}/`;
webpack-contrib/file-loader thuộc nhóm Frontend trên TopGit, cùng 3 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về webpack-contrib/file-loader ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/webpack-contrib/file-loader là nguồn chính thức.
Vì sao webpack-contrib/file-loader được xếp vào nhóm Frontend?
TopGit xếp webpack-contrib/file-loader vào nhóm Frontend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "file", "webpack", "webpack-loader"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
webpack-contrib/file-loader có phải mã nguồn mở không?
Có — webpack-contrib/file-loader phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/webpack-contrib/file-loader.
webpack-contrib/file-loader có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho webpack-contrib/file-loader. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
webpack-contrib/file-loader dùng license gì?
webpack-contrib/file-loader phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
webpack-contrib/file-loader là gì?
webpack-contrib/file-loader (webpack-contrib/file-loader) là dự án JavaScript trên GitHub. Theo mô tả gốc: File Loader
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về file-loader?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về file-loader.