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.

How to output all the assets to a specific directory like `static`?

See original GitHub issue

What problem does this feature solve?

how to change the output assets path?

I mean move dist/js to dist/static/js and dist/css to dist/static/css.

I tried use baseUrl or publicPath option in vue.config.js, but it doesn’t work.

What does the proposed API look like?

provide an option to configure the assetsSubDirectory

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

28reactions
korewayumecommented, Mar 23, 2018
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

/*
  vue inspect --mode production > output.js
  [read some source code](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-service/lib/config)
*/

module.exports = {
  compiler: true,
  devServer: {
    proxy: {
      '/php/': {
        target: process.env.SERVICE_URL,
        changeOrigin: true,
        pathRewrite: {
          '^/php/': '/'
        }
      }
    }
  },
  chainWebpack: webpackConfig => {
    if (process.env.NODE_ENV === 'production') {
      const inlineLimit = 10000;
      const assetsPath = 'static/assets';

      webpackConfig
        .output
        .filename(path.join(assetsPath, 'js/[name].[chunkhash:8].js'))
        .chunkFilename(path.join(assetsPath, '/js/chunk[id].[chunkhash:8].js'))

      webpackConfig.plugin('extract-css')
        .use(ExtractTextPlugin, [{
          filename: path.join(assetsPath, 'css/[name].[contenthash:8].css'),
          allChunks: true
        }])

      webpackConfig.module
        .rule('images')
        .test(/\.(png|jpe?g|gif)(\?.*)?$/)
        .use('url-loader')
        .loader('url-loader')
        .options({
          limit: inlineLimit,
          name: path.join(assetsPath, 'img/[name].[hash:8].[ext]')
        })

      webpackConfig.module
        .rule('fonts')
        .test(/\.(woff2?|eot|ttf|otf)(\?.*)?$/i)
        .use('url-loader')
        .loader('url-loader')
        .options({
          limit: inlineLimit,
          name: path.join(assetsPath, 'fonts/[name].[hash:8].[ext]')
        })
    }
  }
};

15reactions
LucasKauzcommented, Aug 21, 2018

As @rhymes said it has been fixed in Vue CLI 3.

You will need to insert

// vue.config.js
module.exports = {
  assetsDir: 'static'
}

In your configuration to compile assets to the static/ folder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to copy static files to build directory with Webpack?
I'm trying to move from Gulp to Webpack . In Gulp I have task which copies all files and folders from /static/ folder...
Read more >
How to manage static files (e.g. images, JavaScript, CSS)
You can namespace static assets in STATICFILES_DIRS by specifying prefixes. Serving static files during development¶. If you use django.contrib.staticfiles ...
Read more >
Static Asset Handling - Vite
Then you can place the asset in a special public directory under your project root. Assets in this directory will be served at...
Read more >
Serving static files in Express
To serve static files such as images, CSS files, and JavaScript files, ... To use multiple static assets directories, call the express.static middleware ......
Read more >
Static Assets — The Pyramid Web Framework v2.0
In order for files that live in the path directory to be served, a URL that requests one of them must begin with...
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