We could use webpack
without any configuration and that would bundle our JavaScript, but our options will be limited. In this lesson, we'll create a webpack configuration file and we’ll explicitly define the entry point, and some output options as a starting point to build on.
Why is it that in index.js we can use the import
keyword (import greeting from './greet’;
) but in webpack.config.js we can’t, we have to use require
. I tried import path from 'path’;
and `import * as path from 'path'; and both threw errors.
Why is it that in index.js we can use the
import
keyword (import greeting from './greet’;
) but in webpack.config.js we can’t, we have to userequire
. I triedimport path from 'path’;
and `import * as path from 'path'; and both threw errors.
It’s because the webpack config is being run in a node process and node uses require to import modules. The code intended to run in a browser uses ES module syntax and is transformed with Babel into code that will work in a browser environment.
Cool thanks
Hello, don't you need to specified "mode" in your webpack.config.js ?
Hello, don't you need to specified "mode" in your webpack.config.js ?
We cover mode
in the next video