Reputation: 163
I'm using a function (ShowPopUpProject)
in home.html
that defined in javascript.js
.
its never mind what my function is . I just add it in my
webpack.config.js
:
var path = require('path');
var webpack = require('webpack');
module.exports =
{
mode: 'production',
entry: [
'./js/javascript.js',
'./js/javascript2.js',
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: "bundle.js"
}
};
I used ShowPopUpProject
in other functions at javascript2.js
,
when i run run npm build
or webpack
i got error in my bundle.js file :
ReferenceError: ShowPopUpProject is not defined
As you see i defined the function in
javascript.js
and when use injavascript2.js
and build thewebpack
file receive this error. how can i fix this ?
Upvotes: 0
Views: 764
Reputation: 512
Webpack entries are the root of your dependency tree, so what you are telling Webpack is:
If javascript2.js never imports javascript.js then it will not know about the function in javascript.js because it is a separate dependency tree.
If you're really are trying to make two bundles, then use something like [name].js
in output, and use import/require in the files to make sure the functions are defined where they are needed.
Upvotes: 1