@jasen
To work with anchor tags in Webpack, you can use the html-webpack-plugin to automatically inject the anchor tags into your HTML file during the build process. Here is how you can achieve this:
1
|
npm install html-webpack-plugin |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { // other webpack configurations plugins: [ new HtmlWebpackPlugin({ template: 'src/index.html', // path to your HTML file filename: 'index.html', // output HTML file name // add anchor tags here anchorTags: [ '<a href="#section-1">Link to Section 1</a>', '<a href="#section-2">Link to Section 2</a>', // add more anchor tags as needed ] }) ] }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Webpack App</title> </head> <body> <div id="section-1"> <!-- section content --> </div> <div id="section-2"> <!-- section content --> </div> </body> </html> |
Now, when you open the generated index.html file in a browser, you should see the anchor tags that link to the specified sections in your HTML file.