Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
How to add files to the "public folder" in vue 2?

I have a project made in vue.js 2. However there is no public folder; instead, there is a folder named static where you can put files that will be put in the folder /dist/static after you build the staff.

Meanwhile, I need to add a _redirects file to the root of /dist after building, for Netlify integration. However, if I put the file in the root of the project, after building it is ignored. I know that I need to manage something in the config where I have this code:

build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }

I found vue 2 documentation for this rather confuse. The only thing I need is that my new file _redirects gets included in dist folder after building.

Thanks beforehand for the help.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I found the way to do it.

My project uses Webpack with the plugin copy-wepback-plugin. In the documentation of the plugin there is information how to copy files from any path to any path into dist folder after building.

In my case, I added some code in webpack.prod.config.js as shown:

// copy custom static assets
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: config.build.assetsSubDirectory,
        ignore: ['.*']
      },
      { from: path.resolve(__dirname, '../public'), 
        to: config.build.assetsRoot, 
        ignore: ['.*'] }
    ])

So anything that I put in public folder goes copied to root when building.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda