Can't find ngfactory, AOT webpack angular 2

I have an angular wap app and I want to implement AOT compilation of it, the problem is I get an error like - Error: Cannot find module './components/home/home.module.ngfactory'.

im does "node_modules /. bin / ngc" -p tsconfig-aot.json and then builds provider and webpack and launcher app, there is no error in creating or compiling aot folder, i think the problem is that the loader is looking for ngfactory file in main application rather than compiling. Can someone explain how to tell the loader to get the ngfactory files directly from the aot folder, I tried to put the ngfactory file for the home component in the main home folder of the application and it gives other errors with imports in it, but that means it is looking for ngfactory in the main folder. There is my tsconfig-aot.json

{
"compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "noImplicitAny": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es6", "dom" ],
    "suppressImplicitAnyIndexErrors": true
},
"exclude": [
    "ClientApp/boot-client.ts",
    "node_modules",
    "wwwroot"
],
"angularCompilerOptions": {
    "genDir": "aot",
    "entryModule": "USWebTools.Web/ClientApp/app/app.module#AppModule",
    "skipMetadataEmit": true
}

      

and webpack config

    const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const ngToolsWebpack = require('@ngtools/webpack');
var helpers = require('./helpers');

module.exports = () => {
    const isDevBuild = process.env.NODE_ENV !== "production"

// Configuration in common to both client-side and server-side bundles
const sharedConfig = {  
    stats: { modules: false },
    context: __dirname,
    resolve: { extensions: ['.js', '.ts'] },
    output: {
        filename: '[name].js',
        publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
    },
    module: {
        rules: [
            { test: /\.html$/, use: 'html-loader?minimize=false' },
            { test: /\.css$/, use: ['to-string-loader', 'css-loader'] },
            { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
        ].concat(isDevBuild ? [
            { test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] }
        ] : [
                { test: /\.ts$/, loaders: ['@ngtools/webpack'] }
            ])
    },
    plugins: [
        new CheckerPlugin()
    ]
};

// Configuration for client-side bundle suitable for running in browsers
const clientBundleOutputDir = './wwwroot/dist';
const clientBundleConfig = merge(sharedConfig, {
    entry: { 'main-client': './ClientApp/boot-client.ts' },
    output: { path: path.join(__dirname, clientBundleOutputDir) },
    plugins: [
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('./wwwroot/dist/vendor-manifest.json')
        })
    ].concat(isDevBuild ? [
        // Plugins that apply in development builds only
        new webpack.SourceMapDevToolPlugin({
            filename: '[file].map', // Remove this line if you prefer inline source maps
            moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
        })
    ] : [
            new ngToolsWebpack.AotPlugin({
                tsConfigPath: './tsconfig-aot.json',
                entryModule: helpers.root('USWebTools.Web/ClientApp/app/app.module#AppModule')
            }),
            // Plugins that apply in production builds only
            new webpack.optimize.UglifyJsPlugin({
                beautify: false,
                comments: false,
                compress: {
                    screw_ie8: true,
                    warnings: false
                },
                mangle: {
                    screw_ie8: true
                }
            })

        ])
});

return [clientBundleConfig];

      

+3


source to share





All Articles