How to use @ngtools/webpack - 10 common examples

To help you get started, we’ve selected a few @ngtools/webpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shlomiassaf / ngc-webpack / test / lib-usage.spec.ts View on Github external
});
    });

    const config = require(configs.pluginLib.wp)(true);
    const pluginIdx = findPluginIndex(config.plugins);
    const options = {
      skipCodeGeneration: false,
      tsConfigPath: tmpTsConfig
    };
    const plugin = NgcWebpackPlugin.clone(config.plugins[pluginIdx], { options });

    config.plugins.splice(pluginIdx, 1, plugin);

    await run(config);

    Object.defineProperty(WebpackCompilerHost.prototype, 'writeFile', writeFilePropertyDescriptor);

    rimraf.sync(tmpTsConfig);

    // the directory of index.ts:
    const root = Path.dirname(Path.resolve(Path.dirname(configs.pluginLib.ts), tsConfig.files[0]));
    const metadataJsonPath = Path.resolve(root, 'my-lib.ng-flat.metadata.json');
    const meta = await readFile(metadataJsonPath);
    rimraf.sync(metadataJsonPath);

    const metadataBundle: ModuleMetadata = JSON.parse(meta);
    const LibComponentComponent: any = metadataBundle.metadata.LibComponentComponent;

    // flat module with @ngtools/webpack doesn't inline resources into metadata
    expect(LibComponentComponent.decorators[0].arguments[0]).to.eql({
      "selector": "lib-component",
      "templateUrl": "./lib-component.component.html",
github angular / angular-cli / packages / angular_devkit / build_angular / src / angular-cli-files / models / webpack-configs / typescript.ts View on Github external
tsConfigPath: workerTsConfigPath,
    mainPath: undefined,
    platform: PLATFORM.Browser,
    sourceMap: buildOptions.sourceMap.scripts,
    forkTypeChecker: buildOptions.forkTypeChecker,
    contextElementDependencyConstructor: require('webpack/lib/dependencies/ContextElementDependency'),
    logger: wco.logger,
    // Run no transformers.
    platformTransformers: [],
    // Don't attempt lazy route discovery.
    discoverLazyRoutes: false,
  };

  pluginOptions = _pluginOptionsOverrides(buildOptions, pluginOptions);

  return new AngularCompilerPlugin(pluginOptions);
}
github PeterStaev / nativescript-masked-text-field / demo-ng / webpack.config.js View on Github external
uglify, // --env.uglify
        report, // --env.report
        sourceMap, // --env.sourceMap
        hmr, // --env.hmr,
    } = env;
    const externals = (env.externals || []).map((e) => { // --env.externals
        return new RegExp(e + ".*");
    });

    const appFullPath = resolve(projectRoot, appPath);
    const appResourcesFullPath = resolve(projectRoot, appResourcesPath);

    const entryModule = `${nsWebpack.getEntryModule(appFullPath)}.ts`;
    const entryPath = `.${sep}${entryModule}`;

    const ngCompilerPlugin = new AngularCompilerPlugin({
        hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
        platformTransformers: aot ? [nsReplaceBootstrap(() => ngCompilerPlugin)] : null,
        mainPath: resolve(appPath, entryModule),
        tsConfigPath: join(__dirname, "tsconfig.tns.json"),
        skipCodeGeneration: !aot,
        sourceMap: !!sourceMap,
    });

    const config = {
        mode: uglify ? "production" : "development",
        context: appFullPath,
        externals,
        watchOptions: {
            ignored: [
                appResourcesFullPath,
                // Don't watch hidden files
github PeterStaev / NativeScript-Drop-Down / demo-ng / webpack.config.js View on Github external
// when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
    // directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
    // fixes https://github.com/NativeScript/nativescript-cli/issues/4024
    if (env.externals && env.externals.indexOf("@angular/core") > -1) {
        const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName);
        if (appModuleRelativePath) {
            const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
            // include the lazy loader inside app module
            ngCompilerTransformers.push(nsReplaceLazyLoader);
            // include the new lazy loader path in the allowed ones
            additionalLazyModuleResources.push(appModuleFolderPath);
        }
    }

    const ngCompilerPlugin = new AngularCompilerPlugin({
        hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
        platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
        mainPath: resolve(appPath, entryModule),
        tsConfigPath: join(__dirname, tsConfigName),
        skipCodeGeneration: !aot,
        sourceMap: !!sourceMap,
        additionalLazyModuleResources: additionalLazyModuleResources
    });

    const config = {
        mode: uglify ? "production" : "development",
        context: appFullPath,
        externals,
        watchOptions: {
            ignored: [
                appResourcesFullPath,
github PeterStaev / nativescript-image-swipe / demo-ng / webpack.config.js View on Github external
// when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
    // directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
    // fixes https://github.com/NativeScript/nativescript-cli/issues/4024
    if (env.externals && env.externals.indexOf("@angular/core") > -1) {
        const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName);
        if (appModuleRelativePath) {
            const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
            // include the lazy loader inside app module
            ngCompilerTransformers.push(nsReplaceLazyLoader);
            // include the new lazy loader path in the allowed ones
            additionalLazyModuleResources.push(appModuleFolderPath);
        }
    }

    const ngCompilerPlugin = new AngularCompilerPlugin({
        hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
        platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
        mainPath: join(appFullPath, entryModule),
        tsConfigPath: join(__dirname, tsConfigName),
        skipCodeGeneration: !aot,
        sourceMap: !!sourceMap,
        additionalLazyModuleResources: additionalLazyModuleResources
    });

    const config = {
        mode: uglify ? "production" : "development",
        context: appFullPath,
        externals,
        watchOptions: {
            ignored: [
                appResourcesFullPath,
github ng-vcl / ng-vcl / webpack.config.common.js View on Github external
loader: 'postcss-loader',
                options: {
                  ident: 'postcss',
                  parser: 'sugarss',
                  plugins: POSTCSS_PLUGINS,
                  sourceMap: false
                }
              }
            ]
        },
        // TODO: Remove - Ignores System.import warning in angular module
        { test: /[\/\\]@angular[\/\\].+\.js$/, parser: { system: true } },
      ]
    },
    plugins: [
      new AngularCompilerPlugin({
        tsConfigPath: 'tsconfig.json',
        entryModule: path.join(appFolder, '/src/app.module#AppModule'),
        skipCodeGeneration: !aot,
        hostReplacementPaths: replaceEnvFile ? {
          [path.join(appFolder, '/environment/environment.ts')]: path.join(appFolder, `/environment/environment.${replaceEnvFile}.ts`)
        } : {},
      }),
      new MiniCssExtractPlugin(),
      ...(copyAssetsPlugin ? [new CopyWebpackPlugin([{
        from: path.join(appFolder, 'assets/public'),
        to: ''
      }])] : []),
      new webpack.DefinePlugin({
        gitBranch: JSON.stringify(process.env.GIT_BRANCH)
      }),
      new ProgressPlugin(),
github aguskov1987 / arango-graphit / webpack.config.js View on Github external
},
      "lessLoader": {
        "sourceMap": false
      },
      "context": ""
    }
  }));

  if (isProd) {
    plugins.push(new HashedModuleIdsPlugin({
      "hashFunction": "md5",
      "hashDigest": "base64",
      "hashDigestLength": 4
    }));

    plugins.push(new AotPlugin({
      "mainPath": "main.ts",
      "hostReplacementPaths": {
        "environments/index.ts": "environments/index.prod.ts"
      },
      "exclude": [],
      "tsConfigPath": "src/tsconfig.app.json"
    }));

    // plugins.push(new UglifyJsPlugin({
    //   "mangle": {
    //     "screw_ie8": true
    //   },
    //   "compress": {
    //     "screw_ie8": true,
    //     "warnings": false
    //   },
github saxsys / Saxonia-Campus-Angular / webpack.config.js View on Github external
// Also dedupe multiple slashes into single ones.
                return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/');
              }
            })
          ],
          "sassLoader": {
            "sourceMap": false,
            "includePaths": []
          },
          "lessLoader": {
            "sourceMap": false
          },
          "context": ""
        }
      }),
      new AotPlugin({
        "mainPath": "main.ts",
        "exclude": [],
        "tsConfigPath": "src/tsconfig.app.json",
        "skipCodeGeneration": env.aot
      }),
      new NormalModuleReplacementPlugin(
        /environments\/environment/,
        env.env && env.env != 'dev' ? resolve('src', `environments/environment.${env.env}.ts`) : resolve('src', "environments/environment.ts")
      )
    ],
    "node": {
      "fs": "empty",
      "global": true,
      "crypto": "empty",
      "tls": "empty",
      "net": "empty",
github avg-plus / avg.renderer / webpack.config.js View on Github external
context: ""
      }
    })
  );

  if (isProd) {
    // plugins.push(
    //   new HashedModuleIdsPlugin({
    //     hashFunction: "md5",
    //     hashDigest: "base64",
    //     hashDigestLength: 4
    //   })
    // );

    plugins.push(
      new AotPlugin({
        mainPath: "main.ts",
        hostReplacementPaths: {
          "environments/index.ts": "environments/index.prod.ts"
        },
        exclude: [],
        tsConfigPath: "src/tsconfig.app.json",
        skipCodeGeneration: true
      })
    );

    // plugins.push(
    //   new UglifyJsPlugin({
    //     test: /\.js($|\?)/i
    //   })
    // );
  } else {
github fossasia / susper.com / node_modules / @angular / cli / models / webpack-configs / typescript.js View on Github external
return new webpack_1.AngularCompilerPlugin(pluginOptions);
    }
    else {
        const pluginOptions = Object.assign({}, {
            mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
            i18nFile: buildOptions.i18nFile,
            i18nFormat: buildOptions.i18nFormat,
            locale: buildOptions.locale,
            replaceExport: appConfig.platform === 'server',
            missingTranslation: buildOptions.missingTranslation,
            hostReplacementPaths,
            sourceMap: buildOptions.sourcemaps,
            // If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
            exclude: []
        }, options);
        return new webpack_1.AotPlugin(pluginOptions);
    }
}
function getNonAotConfig(wco) {