Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optimise webpack config for examples #98

Merged
merged 2 commits into from
Oct 30, 2024
Merged

Conversation

webdiscus
Copy link
Contributor

Hello @ankurk91 ,

I'm the author of the webpack-remove-empty-scripts that is used in your project.

I want to demonstrate my other html-bundler-webpack-plugin that simplify the Webpack configuration
to generate HTML with assets from source files (templates, scripts, styles, images, fonts, etc.).

The html-bundler-webpack-plugin is the best modern alternative to html-webpack-plugin.

Using the Bundler Plugin, an entry point is an HTML template.
All your source asset files (scripts, styles, images, etc.) can be specified directly in the HTML template using <script> and <link> tags.
The plugin resolves source files of assets in templates and replaces them with correct output URLs in the generated HTML.
The resolved assets will be processed via Webpack plugins/loaders and placed into the output directory.

Using the bundler plugin:

  • An entry point is an HTML template.
  • Binding the source script/style filenames directly in HTML using <script> and <link>.
  • Resolving source asset files specified in attributes href src srcset etc.
  • Inline JS, CSS, SVG, PNG without additional plugins and loaders.
  • Support for any templating engine (Eta, EJS, Handlebars, Nunjucks, LiquidJS, etc.).

Your profit

  • source filenames of scripts and styles can be specified in one right place, in HTML, no need to define them in Webpack entry or import SCSS/CSS in JS file
  • just one plugin replaces the functionality of many plugins and loaders such as:
    • html-webpack-plugin
    • mini-css-extract-plugin
    • html-loader
    • style-loader
    • svg-url-loader
    • TerserPlugin.extractComments
    • and many others

import 'bootstrap/dist/css/bootstrap.min.css';
//import '../src/themes/default/index.scss';
//import '../src/themes/sugar/index.scss';
import '../src/themes/bootstrap/index.scss'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify source SCSS files directly in HTML

@use 'bootstrap/dist/css/bootstrap.min';
//@use '../src/themes/default/index.scss';
//@use '../src/themes/sugar/index.scss';
@use '../src/themes/bootstrap/index.scss'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create the separate SCSS file to bundle many other CSS/SCSS files

module.exports.optimization.minimizer.push(
new TerserPlugin({
include: /\.min\.js$/,
extractComments: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Bundler Plugin already has the extractComments option, defaults is false to avoid extraction of files like *.LICENSE.txt

module.exports.optimization.minimizer.push(
new TerserPlugin({
include: /\.min\.js$/,
extractComments: false,
include: /\.js$/,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the JS file extension to generate minimised JS files in docs/ directory

@ankurk91
Copy link
Owner

Hey,
Thanks for the pull request.
I will review it soon

@webdiscus
Copy link
Contributor Author

Hey, Thanks for the pull request. I will review it soon

You can try the forked branch:

git clone https://github.com/webdiscus/demo-vue-toast-notification.git
cd demo-vue-toast-notification
npm i
npm start

Generate static production files:

npm run docs

@ankurk91 ankurk91 self-requested a review October 30, 2024 07:16
@ankurk91 ankurk91 self-assigned this Oct 30, 2024
@ankurk91 ankurk91 merged commit 28ac7b6 into ankurk91:main Oct 30, 2024
1 check passed
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.13%. Comparing base (4116b16) to head (593df38).
Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #98   +/-   ##
=======================================
  Coverage   67.13%   67.13%           
=======================================
  Files           6        6           
  Lines         143      143           
  Branches       40       41    +1     
=======================================
  Hits           96       96           
  Misses         47       47           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants