Webpack似乎输出了const关键字,而不是输出破坏PhantomJS的var关键字(因为它不支持ES6语法)。
...
/* 2 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
const testing_1 = __webpack_require__(3); // const keyword breaking PhantomJS
testing_1.describe('App', () => {
所以PhantomJS报道
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
SyntaxError: Unexpected token 'const'
有问题的文件(karma-shim.js)正由karma-webpack预处理器处理
果报shim.js
'use strict';
Error.stackTraceLimit = Infinity;
require('es6-shim');
require('angular2/bundles/angular2-polyfills.js');
require('angular2/testing');
var appContext = require.context('./src', true, /root\.spec\.ts/);
appContext.keys().forEach(appContext);
var testing = require('angular2/testing');
var browser = require('angular2/platform/testing/browser');
testing.setBaseTestProviders(browser.TEST_BROWSER_PLATFORM_PROVIDERS, browser.TEST_BROWSER_APPLICATION_PROVIDERS);
karma.conf.js
...
preprocessors: {
'./karma-shim.js': ['webpack', 'sourcemap']
},
tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"moduleResolution": "node",
"jsx": "react"
},
"exclude": [
"node_modules"
],
"compileOnSave": false,
"buildOnSave": false
}
webpack.config.js是generator-ng2-webpack(https://github.com/cmelion/generator-ng2-webpack)的一部分,但似乎没有提及转换。
为什么webpack会输出const而不是var,我可以做些什么来帮助PhantomJS?