如何解决在Rails 6中提供Webpacker图像
我在app/assets/images/letter.png
中有一个文件,我正在尝试在React组件中提供该文件。
我希望文件加载器是在这里使用的正确选择。
// loaders/assets.js
const { env,publicPath } = require('../configuration.js')
module.exports = {
test: /\.(jpg|jpeg|png|gif|svg|eot|ttf|woff|woff2)$/i,use: [{
loader: 'file-loader',options: {
publicPath,name: env.NODE_ENV === 'production' ? '[name]-[hash].[ext]' : '[name].[ext]'
}
}]
}
它在我的组件中输出的URL是:
http://localhost:3000/Users/amirsharif/Projects/sendapostcardonline/public/packsmedia/images/letter-599b40cf9aba6c364ac2bfb054d291d7.png
这显然是非常错误的。 正确路径(预期)为:
http://localhost:3000/packs/media/images/letter-599b40cf.png
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets','engine/foo/app/assets']
resolved_paths: ["app/assets"]
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extract_css: true
extensions:
- .jsx
- .js
- .sass
- .scss
- .css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: false
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: true
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
"Access-Control-Allow-Origin": "*"
watch_options:
ignored: "**/node_modules/**"
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。