alishir

alishir OP

Hi all,

I created new phoenix project, and then added vuejs to it. Vue library loads successfully. But when I set background-image: url('../static/images/test.svg') in my app.css, I didn’t see background image in the result.

I inspected the output html in my browser and it seems that, the file-loader or css-loader sets invalid path in generated css. The background-image value is url([object Object]).

Here is my webpack.config.js file:

const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = (env, options) => ({
	optimization: {
		minimizer: [
			new TerserPlugin({ cache: true, parallel: true, sourceMap: false }),
			new OptimizeCSSAssetsPlugin({})
		]
	},
	entry: {
		'./js/app.js': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
	},
	output: {
		filename: 'app.js',
		path: path.resolve(__dirname, '../priv/static/js')
	},
	module: {
		rules: [
			{
				test: /\.js$/,
				exclude: /node_modules/,
				use: {
					loader: 'babel-loader'
				}
			},
			{
				test: /\.vue$/,
				loader: 'vue-loader'
			},
			{
				test: /\.css$/,
				use: [MiniCssExtractPlugin.loader, 'css-loader']
			},
			{
				test: /\.(png|svg|jpg|jpeg|gif|woff|woff2|ttf|eot)$/,
				loader: 'url-loader'
			},
		]
	},
	plugins: [
		new MiniCssExtractPlugin({ filename: '../css/app.css' }),
		new CopyWebpackPlugin([{ from: 'static/', to: '../' }]),
		new VueLoaderPlugin()
	]
});


First 2 of 2 Posts Switch mode

kokolegorille

kokolegorille

Hello and welcome,

I guess You are using wrong path… Try with this one

url('../images/test.svg')

#or

url('/images/test.svg')

Anyway using static in the path will not work, as it is the root of static assets.

alishir

alishir OP

Thanks for your reply, I test many path combination but the problem doesn’t fix.

Finally I install latest version of css-loader and url-loader and problem resolved.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement