最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to specify an output filename with the Webpack CLI? - Stack Overflow

programmeradmin3浏览0评论

I want to create a file named background.js inside my build folder. This is the mand I use:

webpack --mode production ./src/background -o ./build/background.js

But this creates a folder named background.js inside my build folder. I didn't find any other flag on the webpack-cli documentation. So how do I specify an output filename with the Webpack CLI?

I want to create a file named background.js inside my build folder. This is the mand I use:

webpack --mode production ./src/background -o ./build/background.js

But this creates a folder named background.js inside my build folder. I didn't find any other flag on the webpack-cli documentation. So how do I specify an output filename with the Webpack CLI?

Share Improve this question asked Dec 17, 2020 at 18:36 Rob BauerRob Bauer 8575 gold badges16 silver badges28 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You could try --output-filename: https://v4.webpack.js/api/cli/#output-options

webpack --mode production --entry src/background/index.js --output-filename background.js -o ./build

Per the docs, here's a list of core flags from v4 that are supported in v5: https://github./webpack/webpack-cli/tree/next/packages/webpack-cli#webpack-5

in the webpack.config.js folder add this on the top,

const path = require("path");

then your Module exports will be:

module.exports = {
module: {
    rules: [ 
        // your rules, eg, babel loder.
    ],
},
    // the main solution
entry: "./src/index.js", // your entry file that you want it to be bundled for production
output: { // the output file path,
    path: path.resolve(__dirname, "build"),// build is your folder name.
    filename: "background.js", // your specific filename to be built in the build folder.
}, };

and finally your package.json build script will be

"build": "webpack --mode production",
发布评论

评论列表(0)

  1. 暂无评论