question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

assetsDir not relative to outputDir

See original GitHub issue

Version

3.0.0-rc.5

Reproduction link

https://github.com/androiddrew/flaskme

Steps to reproduce

Create a project with the following structure:

top_level/
├── backend
│   ├── static
│   └── templates
└── vue_project
    ├── dist
    ├── public
    └── src

With vue.config.js set to :

const path = require("path");

module.exports = {
  outputDir: path.resolve('../../backend/static'), 
  assetsDir: './assets',
  baseUrl: '/',
  runtimeCompiler: undefined,
  productionSourceMap: undefined,
  parallel: undefined,
  css: undefined,
  chainWebpack: config => {
    config.plugin('html')
      .tap(args => {
        args[0].filename = path.resolve('../backend/templates/index.html');
        return args;
      });
  },
}

Build your vue_project. The result is creates an index.html with the correct paths in the href tags, but the static assets are placed relative to the default folder NOT the outputDir defined in your config file.

Setting the vue.config file to:

const path = require("path");

module.exports = {
  outputDir: path.resolve('../../backend/static'),
  assetsDir: '../../backend/static/assets',
  baseUrl: '/',
  runtimeCompiler: undefined,
  productionSourceMap: undefined,
  parallel: undefined,
  css: undefined,
  chainWebpack: config => {
    config.plugin('html')
      .tap(args => {
        args[0].filename = path.resolve('../backend/templates/index.html');
        return args;
      });
  },
}

Will place the static assets in the defined directory however the index.html href values are injected with the assetsDir path.

<link as=script href=/../../backend/static/assets/js/chunk-vendors.fb29d323.js rel=preload>

What is expected?

The expected behavior should be to have the assetsDir be a relative path from your outputDir. If the outputDir is undefined then assetsDir is a relative path from the default assetsDir

What is actually happening?

The assetsDir is being used for two separate items. 1. It is being used as the outputDir for the assets. 2. It is used in the url-loaders that inject your src/href/etc. values.


This directory setup above is for a Vuejs SPA client and a Python backend. The built files should be served by the backend, which necessitates their placement in the backend static and template folders. It is part of a python application that will be distributed as a python package.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
cottrellcommented, Oct 27, 2018

img paths are also wrong in the built files. They are not relative to anything so you can not move.

1reaction
ghenrycommented, Oct 27, 2018

I was advised to use baseurl and adjust in my router config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue Cli 3: defined output paths - Stack Overflow
assetsDir. Type: string. Default: ''. A directory (relative to outputDir) to nest generated static assets (js, css, img, fonts) under.
Read more >
Configuration Reference | Vue CLI
A directory (relative to outputDir ) to nest generated static assets (js, css, img, fonts) under. TIP. assetsDir is ignored when overwriting ......
Read more >
[Solved]-Vue Cli 3: defined output paths-Vue.js - appsloveworld
Ref config:assetsDir. assetsDir. Type: string. Default: ''. A directory (relative to outputDir) to nest generated static assets (js, css, img, fonts) under.
Read more >
Configuring Vite
Relative alias values will be used as-is and will not be resolved into ... By default, Vite will empty the outDir on build...
Read more >
vue.config.js configuration - DevPress - CSDN
After the vue-cli3 scaffold is erected, there is no Vue in the project ... outputDir: 'dist', // Output file directory assetsDir: 'static', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found