Socket
Socket
Sign inDemoInstall

ngc-webpack

Package Overview
Dependencies
3
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

index.d.ts

6

package.json
{
"name": "ngc-webpack",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"main": "src/main.js",
"typings": "src/main.d.ts",
"main": "index.js",
"typings": "index.d.ts",
"bin": {

@@ -8,0 +8,0 @@ "ngc-w": "./src/main.js"

@@ -56,2 +56,3 @@ # Angular Template Compiler Wrapper for Webpack

> `ngc-webpack` does not care about SCSS, LESS or any intermediate resource that requires transformation. Each resource will follow the chain defined in the webpack configuration supplied. You get identical result in but development and prod (with AOT) builds.

@@ -69,3 +70,36 @@ ## Usage

### Plugin
`ngc-webpack` comes with an optional plugin called `NgcWebpackPlugin`
The plugin allows hooking into the resource compilation process.
Currently, the only feature is path transformation, i.e: given a path to a resource, return a different path.
The `pathTransformer` hooks is a callback that get's a path (string) and return a path (different to same).
If the returned path is an empty string ('') the content of the resource is ignored and will resolve to an empty string.
Example (webpack.config module)
```js
const NgcWebpack = require('ngc-webpack');
module.exports = function () {
return {
/* All webpack configuration stuff... */
plugins: [
/* Webpack plugins here... */
new NgcWebpack.NgcWebpackPlugin({
pathTransformer: function(resourcePath) {
/*
If we compile a material button, remove it style.
*/
const MAT_BUTTON_RE = /(^.*\/node_modules\/@angular\/material\/button\/button\.css$)/;
if (MAT_BUTTON_RE.test(resourcePath)) {
return '';
}
return resourcePath;
}
})
]
}
}
```
## Why

@@ -80,2 +114,2 @@ In the future I hope we all converge into 1 solution, `@ngtools/webpack`, if you have no issues with it, you don't need `ngc-wrapper`.

> NOTE: I strongly suggest trying to use `@ngtools/webpack` if it works for you stay with it.
My bet is that it will be the de-facto tool for AOT with webpack.
My bet is that it will be the de-facto tool for AOT with webpack.
import { ModuleResolutionHost } from 'typescript';
import { ModuleResolutionHostAdapter } from '@angular/compiler-cli';
export declare class WebpackChainModuleResolutionHostAdapter extends ModuleResolutionHostAdapter {
compiler: any;
private _loader;
private _pathTransformer;
constructor(host: ModuleResolutionHost, webpackConfig: any);
readResource(path: string): Promise<string>;
}

@@ -10,6 +10,3 @@ "use strict";

var webpack_resource_loader_1 = require('./webpack-resource-loader');
function getLoader(config) {
var compiler = webpack(config());
return new webpack_resource_loader_1.WebpackResourceLoader(compiler.createCompilation());
}
var plugin_1 = require('./plugin');
var WebpackChainModuleResolutionHostAdapter = (function (_super) {

@@ -19,5 +16,17 @@ __extends(WebpackChainModuleResolutionHostAdapter, _super);

_super.call(this, host);
this._loader = getLoader(webpackConfig);
this.compiler = webpack(webpackConfig());
this._loader = new webpack_resource_loader_1.WebpackResourceLoader(this.compiler.createCompilation());
var plugin = this.compiler.options.plugins
.filter(function (p) { return p instanceof plugin_1.NgcWebpackPlugin; })[0];
if (plugin && typeof plugin.options.pathTransformer === 'function') {
this._pathTransformer = plugin.options.pathTransformer;
}
}
WebpackChainModuleResolutionHostAdapter.prototype.readResource = function (path) {
if (this._pathTransformer) {
path = this._pathTransformer(path);
if (path === '') {
return Promise.resolve(path);
}
}
return this._loader.get(path);

@@ -24,0 +33,0 @@ };

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc