Python 3.x asset_url_for()在烧瓶饼干切割器(烧瓶网页包)中不返回任何内容
我是新来的网页包。Im使用的是依次使用的Python 3.x asset_url_for()在烧瓶饼干切割器(烧瓶网页包)中不返回任何内容,python-3.x,flask,webpack,Python 3.x,Flask,Webpack,我是新来的网页包。Im使用的是依次使用的 我在该应用程序中遇到问题,无法在开发中找到我的图像。 图像位于资产/img文件夹中 我试过使用{asset\u url\u for('img/img\u name.png')}和它的各种变体,但它只返回一个也没有。 我尝试了通常的烧瓶方式{{url\u for('static',filename='img/img\u name.png')} 但我似乎无法接近它们 const path = require('path'); const webpack =
我在该应用程序中遇到问题,无法在开发中找到我的图像。
图像位于
资产/img
文件夹中
我试过使用{asset\u url\u for('img/img\u name.png')}
和它的各种变体,但它只返回一个也没有。我尝试了通常的烧瓶方式
{{url\u for('static',filename='img/img\u name.png')}
但我似乎无法接近它们
const path = require('path');
const webpack = require('webpack');
/*
* Webpack Plugins
*/
const ManifestRevisionPlugin = require('manifest-revision-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// take debug mode from the environment
const debug = (process.env.NODE_ENV !== 'production');
// Development asset host (webpack dev server)
const publicHost = debug ? 'http://0.0.0.0:2992' : '';
const rootAssetPath = path.join(__dirname, 'assets');
module.exports = {
// configuration
context: __dirname,
entry: {
main_js: './assets/js/main',
main_css: [
path.join(__dirname, 'node_modules', 'materialize-css', 'dist', 'css', 'materialize.css'),
path.join(__dirname, 'assets', 'css', 'style.css'),
],
},
output: {
path: path.join(__dirname, 'dsi_website', 'static', 'build'),
publicPath: `${publicHost}/static/build/`,
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].js',
},
resolve: {
extensions: ['.js', '.jsx', '.css'],
},
devtool: 'source-map',
devServer: {
headers: { 'Access-Control-Allow-Origin': '*' },
},
module: {
rules: [
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: debug,
},
},
'css-loader!less-loader',
],
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: debug,
},
},
'css-loader',
],
},
{
test: /\.html$/,
loader: 'raw-loader'
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff'
}
},
{
test: /\.(ttf|eot|svg|png|jpe?g|gif|ico)(\?.*)?$/i,
loader: `file-loader?context=${rootAssetPath}&name=[path][name].[hash].[ext]`
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['env'],
cacheDirectory: true
}
},
],
},
plugins: [
new MiniCssExtractPlugin({ filename: '[name].[hash].css', }),
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }),
new ManifestRevisionPlugin(path.join(__dirname, 'dsi_website', 'webpack', 'manifest.json'), {
rootAssetPath,
ignorePaths: ['/js', '/css'],
}),
].concat(debug ? [] : [
// production webpack plugins go here
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
}
}),
]),
};
我也遇到了同样的问题,通过更新/升级和在下一个文件中添加来解决:
webpack.config.js
如下:
ManifestRevisionPlugin(path.join(__dirname, '<your app>', 'webpack', 'manifest.json'), {
rootAssetPath,
ignorePaths: ['/js', '/css'],
extensionsRegex: /\.(jpe?g|png|gif|svg)$/i
}),
之后,我检查启动屏幕,我看到我所有的图像加载正确
[WEBPACK] _/assets/img/image_name.20aed528d50316c91ffedb5ba47b8c74.jpg 18.9 KiB [emitted]
是的,忘了这个。是的,该解决方案存在于烧瓶饼干切割器中的问题中。我没有必要更新/升级npm,只是扩展正则表达式起了作用。
[WEBPACK] _/assets/img/image_name.20aed528d50316c91ffedb5ba47b8c74.jpg 18.9 KiB [emitted]