Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
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
// 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,
// 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,
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(),
debug: false,
options: {
/**
* Apply the tslint loader as pre/postLoader
* Reference: https://github.com/wbuchwalter/tslint-loader
*/
tslint: {
emitErrors: false,
failOnHint: false
},
}
})
];
if (isProd)
config.plugins.push(new AngularCompilerPlugin({
tsConfigPath: root('tsconfig.json'),
entryModule: aotEntryModule
}));
if (!isTest && !isTestWatch) {
config.optimization.runtimeChunk = 'single';
config.optimization.splitChunks = {
name : false,
cacheGroups: {
}
};
allEntries.filter(function(e) {return !!e.filter; }).forEach(function(entry) {
config.optimization.splitChunks.cacheGroups[entry.name] = {
test: entry.filter,
name: entry.name,
chunks: 'all', minSize:0, minChunks: 1, reuseExistingChunk: true, enforce: true
"sourceMap": true,
"tsConfigPath": "src/tsconfig.app.json",
"skipCodeGeneration": true,
"compilerOptions": {},
"hostReplacementPaths": {
"environments/index.ts": "environments/index.prod.ts"
},
"exclude": []
}));
plugins.push(new UglifyJsPlugin({
"sourceMap": false
}));
} else {
plugins.push(new AngularCompilerPlugin({
"mainPath": "main.ts",
"platform": 0,
"sourceMap": true,
"tsConfigPath": "src/tsconfig.app.json",
"skipCodeGeneration": true,
"compilerOptions": {},
"hostReplacementPaths": {
"environments/index.ts": "environments/index.ts"
},
"exclude": []
}));
}
return plugins;
}
platform:
buildOptions.platform === 'server' ? PLATFORM.Server : PLATFORM.Browser,
missingTranslation: buildOptions.i18nMissingTranslation,
sourceMap: buildOptions.sourceMap.scripts,
additionalLazyModules,
nameLazyFiles: buildOptions.namedChunks,
forkTypeChecker: buildOptions.forkTypeChecker,
contextElementDependencyConstructor: require('webpack/lib/dependencies/ContextElementDependency'),
logger: wco.logger,
directTemplateLoading: true,
...options
};
pluginOptions = _pluginOptionsOverrides(buildOptions, pluginOptions);
return new AngularCompilerPlugin(pluginOptions);
}
};
const additionalLazyModules = {};
if (buildOptions.lazyModules) {
for (const lazyModule of buildOptions.lazyModules) {
additionalLazyModules[lazyModule] = path.resolve(root, lazyModule);
}
}
const hostReplacementPaths = {};
if (buildOptions.fileReplacements) {
for (const replacement of buildOptions.fileReplacements) {
hostReplacementPaths[replacement.replace] = replacement.with;
}
}
const pluginOptions = Object.assign({ mainPath: useMain ? path.join(root, buildOptions.main) : undefined }, i18nFileAndFormat, { locale: buildOptions.i18nLocale, platform: buildOptions.platform === 'server' ? webpack_1.PLATFORM.Server : webpack_1.PLATFORM.Browser, missingTranslation: buildOptions.i18nMissingTranslation, sourceMap: buildOptions.sourceMap, additionalLazyModules,
hostReplacementPaths, nameLazyFiles: buildOptions.namedChunks, forkTypeChecker: buildOptions.forkTypeChecker, contextElementDependencyConstructor: require('webpack/lib/dependencies/ContextElementDependency') }, options);
return new webpack_1.AngularCompilerPlugin(pluginOptions);
}
function getNonAotConfig(wco, host) {