Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
angular-webpack-transformer
Advanced tools
This plugin allows you to asynchronously change the configuration of the angular webpack
The angular-webpack-transformer
package is a plugin that allows for asynchronous changes to the webpack configuration of an Angular project. It is dependent on the ngx-build-plus package and its documentation should be consulted for further information.
To get started, ngx-build-plus
must be installed and configured, followed by the installation and configuration of angular-webpack-transformer
. After that, create a file named webpack.transformer.js
in the root of your project.
The webpack.transformer.js
file should export a function that utilizes the use function provided by angular-webpack-transformer
to make changes to the webpack config
.
The example file provided below adds a postcss-loader and configures the sass-loader by adding the additionalData
option and also add two new preloaders svg-sprite-loader and svgo-loader for generating svg sprites
const { types, rules } = require('angular-webpack-transformer');
const path = require('path');
module.exports = function (config, use) {
// Sync
rules.modifyOrAddLoader([types.RuleTestTypes.Sass, types.RuleTestTypes.Scss, types.RuleTestTypes.Css], 'postcss-loader', (loader, rule) => {
if (loader) {
return "postcss-loader";
} else {
rule.unshift({
loader: require.resolve('postcss-loader')
});
}
}, config);
// Async
use(async config => {
return rules.modifyOrAddLoader([types.RuleTestTypes.Sass, types.RuleTestTypes.Scss], 'sass-loader', (sassLoader, rule) => {
if (sassLoader) {
sassLoader.options.additionalData = (content, loader) => {
//
}
return sassLoader;
}
}, config);
});
use(async config => {
return rules.modifyOrAddLoader([types.RuleTestTypes.Svg], 'svg-sprite-loader', (loader, rule) => {
if (!loader) {
rule.push({
loader: 'svg-sprite-loader',
options: {
symbolId: filePath => "app-" + path.basename(filePath, path.extname(filePath))
}
});
rule.push('svgo-loader');
}
}, config);
});
}
and finally use --plugin option ng serve --plugin angular-webpack-transformer
or ng build --plugin angular-webpack-transformer
, example of packages.json
:
"scripts": {
"start": "ng serve --plugin angular-webpack-transformer --extra-webpack-config webpack.partial.js -o"
}
This package can be useful for developers who need to make custom changes to their webpack config and want an easy way to do so, without having to manually modify the config file. Additionally, the ability to asynchronously make changes to the config allows for a more efficient development process.
Please note that simply adding the postcss
and postcss-loader
, svg-sprite-loader
, svgo-loader
to your configuration file is not enough. You must also ensure that they are installed in your project by running the command "npm i postcss postcss-loader"
. Once that is done, you can use the file postcss.config.js
to customize your postcss plugins. For example, you can use this file to add plugins such as autoprefixer
or cssnano
to your project
// postcss.config.js
const autoprefixer = require('autoprefixer');
const postcssRtlLogicalProperties = require('postcss-rtl-logical-properties');
const postcssRTL = require('postcss-rtl');
module.exports = () => {
return {
plugins: [
postcssRtlLogicalProperties(),
autoprefixer(),
postcssRTL({
blacklist: postcssRtlLogicalProperties.ignoreDeclarationList,
addPrefixToSelector: (selector, prefix) => {
return `${prefix} ${selector}`;
}
})
]
}
}
and for the svgo plugin, you can create the svgo.config.js
file in the root of the project:
module.exports = {
datauri: 'enc', // 'base64' (default), 'enc' or 'unenc'.
js2svg: {
indent: 1, // string with spaces or number of spaces. 4 by default
pretty: false, // boolean, false by default
},
plugins: [
// set of built-in plugins enabled by default
'preset-default',
// or by expanded notation which allows to configure plugin
"removeTitle",
"removeDesc",
"removeEmptyAttrs",
"removeEmptyText",
"removeEmptyContainers",
"removeStyleElement",
"removeRasterImages",
"removeScriptElement",
{
"name": "removeAttrs",
"params": {
attrs: '(fill|stroke|class|style|filter)'
}
}
]
}
The function from webpack.transformer.js
accepts two parameters:
module.exports = async function (config, use) {
return config;
}
The first parameter is the webpack config that can be modified, and the second parameter, "use,"
is a method that passes the config to a callback for processing. This callback is also asynchronous.
The following example shows how to use the use method:
const { types, rules } = require('angular-webpack-transformer');
module.exports = async function (config, use) {
use(async config => {
return rules.modifyOrAddLoader([types.RuleTestType.Sass, types.RuleTestType.Scss, types.RuleTestType.Css], 'postcss-loader', (loader, rule) => {
if (loader) {
return "postcss-loader";
} else {
rule.unshift({
loader: require.resolve('postcss-loader')
});
}
}, config);
});
}
The method Rules.modifyOrAddLoader
searches for webpack loaders and provides a callback for their modification. The first callback is the loader, and the second is an array of rules. If the first element is found, return it back, otherwise, you can manually modify the array of rules.
The method Rules.find
searches for rules in the config using a regexp
.
The types can be found in the file src/utils/types.ts
FAQs
This plugin allows you to asynchronously change the configuration of the angular webpack
The npm package angular-webpack-transformer receives a total of 1 weekly downloads. As such, angular-webpack-transformer popularity was classified as not popular.
We found that angular-webpack-transformer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.