Skip to content

Chunks are not getting generated with @ngtools/webpack #8563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
krischandra opened this issue Nov 21, 2017 · 11 comments
Closed

Chunks are not getting generated with @ngtools/webpack #8563

krischandra opened this issue Nov 21, 2017 · 11 comments
Labels
needs: repro steps We cannot reproduce the issue with the information given

Comments

@krischandra
Copy link

Versions

Angular CLI: 1.5.0
Node: 6.10.1
Angular 5
@ngtools/webpack version: 1.8.2

Webpack.common.js
module: {
rules: [{
loader: '@ngtools/webpack',
options: {
configFileName: 'tsconfig.webpack.json',
}
}],
plugins: [{
new AngularCompilerPlugin({
"sourceMap": true,
"tsConfigPath": helpers.root('tsconfig.webpack.json'),
"skipCodeGeneration": true,
"compilerOptions": {}
}),
}]
}
Actual result: Chunks is not getting generated for lazy loaded modules
Expected Result: Should generate chunks

@KrakenTyio
Copy link

pls post tsconfig.webpack.json
maybe there is problem

@krischandra
Copy link
Author

krischandra commented Nov 21, 2017

{
"compilerOptions": {
"outDir": "./compiled",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"baseUrl": ".",
"paths": {
"@root/:[
"src/root/
"
],
"@main/": [
"src/main/
"
],
"@test/": [
"src/test/
"
],
"@styles/": [
"src/style-sheets/
"
]
},
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2015",
"dom"
]
},
"exclude": [
"node_modules",
],
"angularCompilerOptions": {
"genDir": "./compiled",
"skipMetadataEmit": true
},
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}

Do i need to use @angularclass/hmr-loader, ng-router-loader, angular2-template-loader while using
ngtools/webpack to generate chunks?. If so what should be the order do we need to follow?

Thanks in advance

@KrakenTyio
Copy link

KrakenTyio commented Nov 21, 2017

tsconfig looks good.
Extra routing template loaders are no needed for new ngtools.

Maybe you have wrong defined routers.

@EmaGht
Copy link
Contributor

EmaGht commented Nov 22, 2017

Actually having the same problem here...

webpack:

var webpack = require("webpack");
var path = require("path");
var clone = require("js.clone");
var merge = require("webpack-merge");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var ContextReplacementPlugin = require("webpack/lib/ContextReplacementPlugin");
var TsConfigPathsPlugin = require("awesome-typescript-loader").TsConfigPathsPlugin;
var CheckerPlugin = require("awesome-typescript-loader").CheckerPlugin;
var DefinePlugin = require("webpack/lib/DefinePlugin");
var CopyWebpackPlugin = require("copy-webpack-plugin");
var isDevBuild = process.env.ASPNETCORE_ENVIRONMENT === "Production" ? false : true;
var isAotBuild = false;
var AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;

module.exports = (env) => {

  if (env && env.prod)
    isDevBuild = false;

  if (env && env.aot) {
    isAotBuild = true;
  }
  var distDirectory = "./wwwroot/dist";
  var defaultLoaders = ["awesome-typescript-loader?silent=true", "angular2-template-loader", "angular-router-loader"];

  var sharedConfig = {
    resolve: {
      extensions: [".js", ".ts", ".css", ".scss", ".json"]
    },

    stats: { modules: false },
    context: __dirname,

    output: {
      filename: "[name].js",
      publicPath: "/dist/"
    },

    module: {
      loaders: [
        { test: /\.ts$/, use: isDevBuild ? defaultLoaders : isAotBuild ? '@ngtools/webpack' : defaultLoaders },
        { test: /\.html$/, use: "raw-loader" },
        { test: /\.css/, use: "raw-loader" },
        { test: /\.scss$/, use: ["raw-loader", "sass-loader"] },
        { test: /initial\.scss$/, use: ExtractTextPlugin.extract({ fallback: "style-loader", use: "css-loader!sass-loader?sourceMap" }) },
        { test: /\.json$/, use: "json-loader" },
        { test: /\.woff(2)?(\?v=.+)?$/, use: "url-loader?limit=10000&mimetype=application/font-woff&name=fonts/[name].[ext]" },
        { test: /\.(ttf|eot|svg)(\?v=.+)?$/, use: "file-loader?&name=fonts/[name].[ext]" },
        { test: /bootstrap\/dist\/js\/umd\//, use: "imports?jQuery=jquery" },
        { test: /\.(png|jpg|gif)$/, use: "file-loader?limit=8192&name=assets/img/[name].[ext]" }
      ]
    },

    plugins: [ new CheckerPlugin() ]
  };

  var clientConfig = setTypeScriptAlias(require("./tsconfig.json"), {

    entry: {
      'main-client': "./Client/bootstrap-client.ts"
    },

    output: {
      path: path.join(__dirname, distDirectory),
      filename: "[name].js",
      publicPath: "/dist/"
    },

    plugins: [
      new DefinePlugin({ 'process.env': { 'development': true } }),
      new ContextReplacementPlugin(
        // The (\\|\/) piece accounts for path separators in *nix and Windows
        /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
        root("./Client")
      ),
      new TsConfigPathsPlugin({ tsconfig: "tsconfig.json" }),
      new webpack.DllReferencePlugin({
        context: __dirname,
        manifest: require("./wwwroot/dist/vendor-manifest.json")
      })

    ].concat(isDevBuild ?
      [
        new webpack.SourceMapDevToolPlugin({ filename: "[file].map", moduleFilenameTemplate: path.relative(distDirectory, "[resourcePath]") })
      ] :
      [
        new webpack.optimize.UglifyJsPlugin()
      ]
      ).concat(isAotBuild ?
        [
          new AngularCompilerPlugin({
            tsConfigPath: './tsconfig.json',
            entryModule: path.join(__dirname, 'Client/app/platform-modules/app.browser.module#AppBrowserModule'),
            exclude: ['./**/*.server.ts']
          })
        ] :
        [])
  });

  // Merge with Shared
  var mergedClientConfig = merge(sharedConfig, clientConfig);

  return [mergedClientConfig];
};

function setTypeScriptAlias(tsConfig, config) {
  var newConfig = clone(config);
  newConfig = newConfig || {};
  newConfig.resolve = newConfig.resolve || {};
  newConfig.resolve.alias = newConfig.resolve.alias || {};
  var tsPaths = tsConfig.compilerOptions.paths;
  for (var prop in tsPaths) {
    newConfig.resolve.alias[prop] = root(tsPaths[prop][0]);
  }
  return newConfig;
}

function root(args) {
  args = Array.prototype.slice.call(arguments, 0);
  return path.join.apply(path, [__dirname].concat(args));
}

scripts i use to compile:

    "build:dev": "webpack --config webpack.config.vendor.js --progress && webpack --config webpack.config.js --progress",

    "build:prod": "webpack --config webpack.config.vendor.js --progress --env.prod && webpack --config webpack.config.js --env.prod --progress",

    "build:prod:aot": "webpack --config webpack.config.vendor.js --progress --env.prod && webpack --config webpack.config.js --env.prod --env.aot --progress"

results for :dev are
builddev

results for :prod are:
buildprod

results for prod:aot are...
buildaot

As you can see it's not generating the chunks in AOT mode.
Strange thing is AOT compilation throws no error whatsoever...

@filipesilva
Copy link
Contributor

There was a similar issue (#8597) where the problem was ContextReplacementPlugin. If that's not the problem in your case, could you set up a repro that I can clone to see the problem please?

@filipesilva filipesilva self-assigned this Nov 24, 2017
@filipesilva filipesilva added the needs: repro steps We cannot reproduce the issue with the information given label Nov 24, 2017
@EmaGht
Copy link
Contributor

EmaGht commented Nov 24, 2017

Actually i was following the thread you linked aswell.
In my case, tho, the problem was this:

new webpack.DllReferencePlugin({ context: __dirname, manifest: require("./wwwroot/dist/vendor-manifest.json") })

I'm not really sure about what it does... i just took it from another template a couple months ago, but that was my deal-breaker.
Thanks for your interest!!

@filipesilva
Copy link
Contributor

@EmaGht the @ngtools/webpack plugin is unfortunately not compatible with the DLLPlugin: #4565

@sjumble
Copy link

sjumble commented Feb 23, 2018

Hey @EmaGht have you resolved this issue, if Yes then can you please let us know the solutions.

@EmaGht
Copy link
Contributor

EmaGht commented Feb 24, 2018

@sjumble I just excluded the DllReference plugin from the plugin chain during aot build, you can see my webpack configuration in my rant about the current state of node's package manager here: yarnpkg/yarn#2088

@alan-agius4
Copy link
Collaborator

Closing as no re-production was provided.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: repro steps We cannot reproduce the issue with the information given
Projects
None yet
Development

No branches or pull requests

6 participants