组件未在Angular 2 app AoT编译中加载

时间:2017-09-25 13:41:00

标签: javascript angular aot rollupjs

我按照网站上的步骤' https://angular.io/guide/aot-compiler'调整Angular 2应用程序以使用AoT编译,一切似乎按预期工作,直到汇总步骤,理论上清理未使用组件的代码。

离开' rollup-config.js'文件与说明中的相同,当我运行“node_modules / .bin / rollup -c rollup-config.js'我收到以下错误:

  

[!]错误:' ToastModule'不是由node_modules / ng2-toastr / ng2-toastr.js导出

我用谷歌搜索了它,我遇到了一个解决方案,指出要添加一个名为“导出”的解决方案。 ' commonjs'参数。由此产生的' rollup-config.js'是:

import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';

export default {
    entry: 'src/main.js',
    dest: 'src/build.js',
    sourceMap: false,
    format: 'iife',
    onwarn: function(warning) {
        if(warning.code === 'THIS_IS_UNDEFINED') { return; }

        console.warn(warning.message);
    },
    plugins: [
        nodeResolve({jsnext: true, module: true}),
        commonjs({
            include: 'node_modules/**',
            namedExports: {
                'node_modules/ng2-toastr/ng2-toastr': [ 'ToastModule' ]
            }
        }),
        uglify()
    ]
}

现在,该脚本会生成' build.js'文件,我可以通过index.html文件加载它,但组件' ng2-toastr'无法正常工作(该组件会显示一条' toast' like信息,出现在屏幕的一侧并在几秒钟后消失。)

我错过了什么吗?提前谢谢,

0 个答案:

没有答案