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

135
Visualizações
Webpack: use data from parent directory without copying

I have a project folder structured like this:

project-name/   
  data/
   data.csv
  dist/
   index.js
  src/
   index.js

And want a remote directory like this:

project-name/   
  data/
   data.csv
  dist/
   index.js
    > `doSomething("../data/data.csv")`

How do I make this work in both webpack-dev-server and in the production path? If I use copywebpack plugin, then the data goes inside the dist/, which I don't want. But if I use a relative directory without copying the data, then the build fails.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Actually, you should use Webpack csv-loader in your Webpack configuration file like below:

module: {
  rules: [
    {
      test: /\.csv$/,
      loader: 'csv-loader',
      options: {
      dynamicTyping: true,
        header: true,
        skipEmptyLines: true,
      },
    },
  ],
},

And then use it inside your code like below:

import csvPath from './project-name/data/foo.csv'
about 4 years ago · Juan Pablo Isaza Relatório

0

Can you use an alias?

webpack.config.js:

  const path = require("path");

  module.exports = {
  ...

    resolve: {
      alias: {
        Data: path.resolve(__dirname, "./project-name/data/"),
      },
    },
  }

src/index.js:

  import data from "Data/data.csv"
about 4 years ago · Juan Pablo Isaza Relatório

0

Have you tried excluding it in the test? Something like this:

   {
    entry: "./src/index.js",
    module: {
      rules: [
        {
          test: /\.js$/,
          use: ["babel-loader or whatever loader you use"],
        },
        {
          test: /\.csv$/,
          exclude: ["./data/"],
        },
      ],
    },
    output: {
      filename: "index.js",
      path: path.resolve(__dirname, "dist"),
    },
   },

There is a similar question on how to not bundle files in webpack here

about 4 years ago · Juan Pablo Isaza 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