Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda