【发布时间】:2017-02-24 04:44:43
【问题描述】:
抱歉,这个问题已经被问过很多次了。在过去的几天里,我做了很多尝试来让它工作,但我觉得我错过了一些微不足道的事情,这使得这变得不可能。
背景: 使用 .NET Core 作为 Angular2 前端和 webpack 2.2.1 的后端来部署 js/css。 (顺便说一句,我正在使用以下模板,http://blog.stevensanderson.com/2016/10/04/angular2-template-for-visual-studio/)
我正在尝试使用以下内容将 alertifyjs 引用到打字稿服务 (notifications.service.ts) 中:
import { Injectable } from '@angular/core';
//import * as alertify from 'alertifyjs';
declare var alertify: any;
//var alertify = require('alertify.js');
@Injectable()
export class NotificationService {
private _notifier: any = alertify;
constructor() {
}
所以我目前的问题是我该怎么做:
-
检查 alertifyjs 是否真的通过 webpack 正确呈现(我尝试通过开发人员工具的控制台调用 alertify,但没有成功)-这不是必需的,但它很好的学习
让 alertify 通过 webpack 正常工作
- 在 Angular2 中引用和使用 alertify
提前感谢您的任何帮助,如果在 StackOverflow 上的某个地方得到了回答,我非常抱歉,我错过了!
另外,我的 webpack 配置如下:
var isDevBuild = process.argv.indexOf('--env.prod') < 0;
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('vendor.css');
module.exports = {
resolve: {
extensions: [ '', '.js' ]
},
resolveLoader: {
debug: true,
},
module: {
loaders: [
{ test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, loader: 'url-loader?limit=100000' },
{ test: /\.css(\?|$)/, loader: extractCSS.extract(['css']) }
]
},
entry: {
vendor: [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/platform-server',
'angular2-universal',
'angular2-universal-polyfills',
'bootstrap',
'bootstrap/dist/css/bootstrap.css',
'es6-shim',
'es6-promise',
'jquery',
'zone.js',
'alertifyjs',
//'systemjs',
'font-awesome/css/font-awesome.css'
]
},
output: {
path: path.join(__dirname, 'wwwroot', 'dist'),
filename: '[name].js',
library: '[name]_[hash]',
},
plugins: [
extractCSS,
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', alertify: 'alertifyjs' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DllPlugin({
path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
name: '[name]_[hash]'
})
].concat(isDevBuild ? [ ] : [
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } })
])
};
【问题讨论】:
标签: c# angular typescript webpack asp.net-core