繁体   English   中英

angularjs不包括node_modules(最小化和注释)

[英]angularjs not including node_modules (minification and annotation)

我正在做一个小的angularjs项目

我使用导入了ngRoute:

npm安装angular-route -S

我的index.js看起来像:

import angular from 'angular';

import {nv_morts} from './components/calculator/mortsList/morts';

import 'angular-route/angular-route';


angular.module('app.starter', ['ngRoute'
]).config(function ($routeProvider) {
    $routeProvider
        .when("/Calculators", nv_morts);
});

webpack.config:

 module: {
     loaders: [

       // load and compile javascript
       { test: /\.js$/, exclude: /node_modules/, loader:"babel", query: { presets: ['es2015', 'stage-1'] } },

       // load css and process less
       { test: /\.css$/, loader: "style!css"},

       // load JSON files and HTML
       { test: /\.json$/, loader: "json" },
       { test: /\.html$/, exclude: /node_modules/, loader:"raw" },

       // load fonts(inline base64 URLs for <=8k)
       { test: /\.(ttf|eot|svg|otf)$/, loader: "file" },
       { test: /\.woff(2)?$/, loader: "url?limit=8192&minetype=application/font-woff"},

       // load images (inline base64 URLs for <=8k images)
       {test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'}
     ]   }

我在package.json中有一个脚本

"scripts": {
    "prestart": "npm install",
    "start": "webpack-dev-server",
    "bundle": "cp src/index.html dist/ & webpack -p ./dist/bundle.js"
  }

当我在本地工作时(localhost:8080),当我执行命令时,一切工作正常

npm运行构建

它在“ dist”文件夹中构建文件index.html&bundle.js

但是当我将此文件放入IIS文件夹时,我得到:

由于以下原因,无法实例化模块app.starter:错误:[$ injector:unpr]未知提供程序:t

如果我删除对ngRoute的依赖,它在IIS上也能正常工作

为什么在最终的bundle.js中不包含ngRoute?

多谢你们

好,所以我解决了:-)

问题出在缩小和注释中。

此链接AngularJs缩小和注释

非常有帮助。

我的代码未使用缩小安全依赖项。

例如:

在index.js中,我应该这样做:

.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when("/Calculators", nv_morts)}]);

当我向其他服务注入服务时,我需要使用与index.js相同的模式

在我注入服务的组件内部,我需要使用$ inject

例如:

class mortsController {

    /* @ngInject */
    constructor(MortsMngr) {
        this.newMortName = '';
        this.mortsManager = MortsMngr;
        this.savedMorts = MortsMngr.mortsList;

        MortsMngr.fetchMortsList();
    }  
}

mortsController.$inject = ['MortsMngr'];

export const nv_morts = {
    bindings: {},
    template: template,
    controller: mortsController,
    controllerAs: 'Morts'
}

注意这一行:

mortsController。$ inject = ['MortsMngr'];

有所不同。

希望它能帮助任何人

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM