Closed 5ulo closed 8 months ago
Hi @5ulo
Right now I use CopyPlugin to copy libs to it's place on build but every file included in src or link is compiled and at the end replaced.
To disable resolving and processing of attributes such as src
, href
etc, you can use the loaderOptions.sources[].filter()
option.
For example:
<!-- must be processed via Bundler Plugin -->
<script src="./scripts/main.js"></script>
<!-- ignore the processing via Bundler Plugin, because is coped into `dist/` using CopyPlugin-->
<script src="myLib/lib.js"></script>
new HtmlBundlerPlugin({
entry: {
index: 'src/views/index.html',
},
loaderOptions: {
sources: [
// exclude JS dir
{
tag: 'script', // <= tag name
filter: ({ attribute, value }) => { // attribute name and attribute value
const libPath = 'myLib/'; // <= path to lib files coped in the `dist/` directory
if (attribute === 'src' && value.includes(libPath) ) return false; // => disable processing
},
},
// exclude CSS dir
{
tag: 'link', // <= tag name
filter: ({ attribute, value }) => { // attribute name and attribute value
const libPath = 'myLib/'; // <= path to lib files coped in the `dist/` directory
if (attribute === 'href' && value.includes(libPath) ) return false; // => disable processing
},
},
],
},
});
Oh.. I use sources but missed that nifty filter. Perfect, thanks!
Feature request
What is motivation or use case for adding/changing the behavior?
Included 3rd party libs (js, css) are minified already or one wont minify them at all, but there's no way to exclude dir containing files like that eg. /libs. Maybe this is already implemented and I am blind or incapable.
Describe the solution you'd like
Have an option to exclude directory from minifyng and resolving paths inside them, just keep watching files for changes.
Describe alternatives you've considered
Right now I use
CopyPlugin
to copy libs to it's place on build but every file included in src or link is compiled and at the end replaced. Used it together withTerserPlugin
but somehow it is ignored or overriden withbundler plugin
.