How to set multiple file entry/output in project with webpack?
I follow http://webpack.github.io/docs/tutorials/getting-started/ success compile if only one file in one entry/output...
directory
app webpack.config.js ./assets ././javascripts/Administrator/Article/Create/Base.js ././javascripts/Administrator/Article/Edit/Base.js ././javascripts/Account/Index/Base.js ././javascripts/Contact/Index/Base.js ...
how to output like this?
././javascripts/Administrator/Article/Create/bundle.js ././javascripts/Administrator/Article/Edit/bundle.js ././javascripts/Account/Index/bundle.js ././javascripts/Contact/Index/bundle.js
webpack.config.js
module.exports = { entry: { 'AdministratorArticleCreate':['./assets/javascripts/Administrator/Article/Create/Base.js'] }, output: { path: } // if only one file // entry: "./assets/javascripts/Administrator/Article/Create/Base.js", // output: { // // path: __dirname, // path: "./assets/javascripts/Administrator/Article/Create/", // filename: "bundle.js" // } };
webpack.config.jsWe can also pass an array of file paths to the entry property which creates what is known as a "multi-main entry". This is useful when you would like to inject multiple dependent files together and graph their dependencies into one "chunk".
You can bundle your JavaScript using the CLI command by providing an entry file and output path. Webpack will automatically resolve all dependencies from import and require and bundle them into a single output together with your app's script.
The __dirname is set to / by webpack, that's why you end up with /views/index. html which is the root of your file system, that happens to be D:\ in your case. You can set node. dirname to false in your webpack config to not inject it and defer it to runtime.
Use webpack-cli's init command to rapidly generate webpack configuration files for your project requirements, it will ask you a couple of questions before creating a configuration file. npx might prompt you to install @webpack-cli/init if it is not yet installed in the project or globally.
For many entry points use arrays as a value of entry
property:
entry: { app: ['./app/main.js', '.lib/index.js'], vendors: ['react'] }
app
and vendors
are arrays, so you can put there as many file paths as you need.
For output case:
output: { path: staticPath, filename: '[name].js' }
The [name]
is taken from entry
properties, so if we have app
and vendors
as properties, we got 2 output files - app.js
and vendors.js
.
Documentation link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With