10

I want to rename the index.html genrated by npm run build. I can't find anything in the webpack config.

I've also create a vue.config.js described here: https://github.com/vuejs/vue-cli/tree/dev/docs/config

module.exports = {
  pages: {
    index: {
      filename: 'dapp.html',
    }
  }
};

But the output file is still index.html

0

2 Answers 2

11

You can just use

module.exports = {
  indexPath: 'index_bundled.html'
}

as a vue cli default option to change the file

Sign up to request clarification or add additional context in comments.

1 Comment

How to dynamic change the index? Like using an "if" statement?
10

Since you are creating a vue.config.js I assume you are using vue-cli 3.0.

Given that you should add the following lines on your vue.config.js.

module.exports = {
    // modify the location of the generated HTML file.
    // make sure to do this only in production.
    chainWebpack: (config) => {
        if (process.env.NODE_ENV === 'production') {
            config.plugin('html').tap((opts) => {
                opts[0].filename = './dist/dapp.html';
                return opts;
            });
        }
     },
};

Creator of Vue has set a laravel-vue-cli-3 example on github https://github.com/yyx990803/laravel-vue-cli-3 where you can take a look

Update for previous version of vue-cli

If you are using vue webpack template then inside config folder there is a index.js file. Inside module.exports you will find the following where you can set your output:

...
build: {
    // Template for index.html
    index: path.resolve(__dirname, './dist/index.html'),

    ...
},

just change index.html with the dapp.html and that should work.

If you are using webpack template you can see more details at http://vuejs-templates.github.io/webpack/backend.html.

3 Comments

I don't use vue-cli 3.x. I've updated to vue-cli 3 to test your solution but it the output was still index.html. Do you know how to fix this with cli version 2.9.6? I will also do some research.
@MarcS82 I have updated my answer for previous version of vue-cli. Hope it helps.
How to dynamic change the index? Like using an "if" statement?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.