Webpack生成的文件错误:" t.replace不是函数"

时间:2016-07-12 12:49:01

标签: angular webpack

我正在使用Webpack处理一些示例Angular 2应用程序,该应用程序生成一些js和css文件。我已成功将我的应用程序作为Web应用程序在JBoss AS 7.1上运行,但当我尝试将其用作WebSphere Portal 7上的portlet应用程序时,发生了以下错误:

enter image description here

我的猜测是replace函数没有在字符串变量上调用(应该如此),但我不知道,为什么会发生这种情况(仅限于门户网站)。

任何人都可以帮我理解上面的堆栈跟踪吗?

如果有帮助,请点击我的Webpack配置:

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');

module.exports = {
    entry : {
        'polyfills' : './src/polyfills.ts',
        'vendor' : './src/vendor.ts',
        'app' : './src/main.ts'
    },

    resolve : {
        extensions : [ '', '.js', '.ts' ]
    },

    devtool: 'source-map',

  output: {
    path: helpers.root('dist'),
    publicPath: '/.AngularPortlet/dist/',
    filename: '[name].[hash].js',
    chunkFilename: '[id].[hash].chunk.js'
  },

  htmlLoader: {
    minimize: false // workaround for ng2
  },

    module : {
        loaders : [ {
            test : /\.ts$/,
            loader : 'ts'
        }, {
            test : /\.html$/,
            loader : 'html'
        }, {
            test : /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
            loader : 'file?name=assets/[name].[hash].[ext]'
        }, {
            test : /\.css$/,
            exclude : helpers.root('src', 'app'),
            loader : ExtractTextPlugin.extract('style', 'css?sourceMap')
        }, {
            test : /\.css$/,
            include : helpers.root('src', 'app'),
            loader : 'raw'
        } ]
    },

    plugins : [ new webpack.optimize.CommonsChunkPlugin({
        name : [ 'app', 'vendor', 'polyfills' ]
    }),

    new HtmlWebpackPlugin({
        xhtml : true,
        minify : {
            keepClosingSlash : true
        },
        template : 'src/index.html',
        favicon : 'public/images/favicon.ico',
        filename : 'index.html'
    }),
    new webpack.NoErrorsPlugin(),
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.UglifyJsPlugin(),
    new ExtractTextPlugin('[name].[hash].css'),
    new webpack.DefinePlugin({
      'process.env': {
        'ENV': JSON.stringify(ENV)
      }
    })  ]

};

Web应用程序的配置是相同的,除了publicPath对于Webpack输出文件略有不同。

xhtml代码(我只是简单地包含生成的index.html代码):

<div xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:portlet="http://java.sun.com/portlet_2_0"
xmlns:p="http://primefaces.org/ui">

<h:form id="formMain">
    <ui:include src="../dist/index.html" />
</h:form>

的index.html

<!DOCTYPE html>
<html>
<head>
<base href="/" />
<title>Angular With Webpack</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" type="text/css"
    href="/.AngularPortlet/node_modules/primeui/primeui-ng-all.min.css" />
<link rel="stylesheet" type="text/css"
    href="/.AngularPortlet/node_modules/primeui/themes/omega/theme.css" />
<link
    href="/.AngularPortlet/node_modules/ag-grid/dist/styles/ag-grid.css"
    rel="stylesheet" type="text/css" />
<link
    href="/.AngularPortlet/node_modules/ag-grid/dist/styles/theme-fresh.css"
    rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="/.AngularPortlet/dist/favicon.ico" />
<link href="/.AngularPortlet/dist/app.f16840a33ca242ab101a.css"
    rel="stylesheet" />
</head>
<body>
    <my-app>Loading...</my-app>
    <script type="text/javascript"
        src="/.AngularPortlet/dist/polyfills.f16840a33ca242ab101a.js"></script>
    <script type="text/javascript"
        src="/.AngularPortlet/dist/vendor.f16840a33ca242ab101a.js"></script>
    <script type="text/javascript"
        src="/.AngularPortlet/dist/app.f16840a33ca242ab101a.js"></script>
</body>
</html>

0 个答案:

没有答案