How to import an entire file (javascript) with Webpack?

Asked

Viewed 133 times

1

I started studying Webpack now, managed to use it normally though, when I want to import something from another file I need to give:

import {abc} from './my-file.js';

and in the file that was imported:

export function abc() {
    console.log('MODULO 1 do projeto');
}

Until then OK. However, how do I import the entire file? No need to specify just the function or variable I want? I want to import the file and be able to use everything in it (variables, functions and etc...).

I tried to give only:

import './my-file.js';

However, it does not recognize anything inside this file, it compiles normally, but error occurs when invoking functions (function has not been defined).

So, is there any way I can import the entire file?

2 answers

1

I managed to solve using Laravel Mix, by some chance if someone has the same doubt, search on Laravel Mix.

Small course on Laravel-mix made by its own creator: https://laracasts.com/series/learn-laravel-mix/

Laravel Mix is a part of the Laravel php framework, however, it is possible to use only Laravel Mix to 'package' in an extremely simple and easy way the files Sass, Less, js and etc... without using the entire Laravel framework

0

Hello! It’s been a long time since the question, but I had the same doubt and in trial and error I got it in the following way:

import * as utils from './uteis.js'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.