Webpack Angular2アプリケーションに問題があります。私はカルマとセットアップをテストしたいが、私はあるバグが発生します。ここではAngular2 Webpack Karma - 予期しないトークン ')'
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
SyntaxError: Unexpected token ')' at src/app/app.component.spec.ts:74
は、私が提供できるすべてです:
package.json:
"karma": "^1.3.0",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "2.2.2",
"karma-phantomjs-launcher": "1.0.2",
"karma-requirejs": "1.1.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.3",
karma.conf .js:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
{ pattern: 'src/**/*spec.ts', watched: false }
],
exclude: [
],
preprocessors: {
'src/**/*spec.ts': ['webpack']
},
reporters: ['progress'],
webpack: require('./config/webpack.dev.js'),
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true,
concurrency: Infinity
})
}
app.component.spec.ts(それは私の全体のファイルである、私はライン74を持っていません):
describe('Meaningful Test',() => {
it('1 + 1 => 2',() => {
expect(1 + 1).toBe(2);
});
});
webpack.dev.js:
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const commonConfig = require('./webpack.common.js');
const helpers = require('./helpers');
const ENV = process.env.NODE_ENV = process.env.ENV = 'development';
module.exports = webpackMerge(commonConfig(), {
output: {
path: helpers.root('dist'),
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
plugins: [
new UglifyJsPlugin({
mangle: {
keep_fnames: true
}
}),
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
})
]
});
webpack.common .js:
const webpack = require('webpack');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const helpers = require('./helpers');
module.exports = function() {
return {
resolve: {
// Array of extensions that will be used to resolve modules
extensions: ['.js', '.ts']
},
// Entry points the bundles
entry: {
'polyfills': helpers.root('src', 'polyfills.ts'),
'vendor': helpers.root('src', 'vendor.ts'),
'app': [
helpers.root('src', 'main.ts'),
helpers.root('src', 'style', 'main.scss')
]
},
module: {
rules: [
// Compiles all .ts files
{
test: /\.ts$/,
loaders: ['ng-router-loader', 'awesome-typescript-loader?silent=true', 'angular2-template-loader'],
exclude: /\.spec\.ts$/
},
// Injects all html templates into their components and loads referenced assets
{
test: /\.html$/,
loader: 'html-loader',
exclude: helpers.root('src/index.html')
},
// Copies all images and fonts into dist/assets
{
test: /\.(png|jpe?g|gif|svg|webm|mp4|woff|woff2|ttf|eot)$/,
loader: 'file-loader?name=assets/[name].[ext]'
},
// Puts all styles from assets/styles/main.scss in a separate file
{
test: /\.scss$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader'])
},
// Injects all angular styles into their components
{
test: /\.scss$/,
include: helpers.root('src', 'app'),
loaders: ['raw-loader', 'sass-loader']
},
// Loads all "required" json files into their components
{
test: /\.json$/,
loader: 'json-loader'
}
]
},
node: {
console: true,
fs: 'empty',
net: 'empty',
tls: 'empty'
},
plugins: [
// File name for the extracted styles
new ExtractTextPlugin('[name].css'),
// Identifies common modules and puts them into a commons chunk
/* new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}), */
// Provides context to Angular's use of System.import
new ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('src')
),
// Generates an HTML5 file that includes all webpack bundles
new HtmlWebpackPlugin({
template: helpers.root('src', 'index.html'),
favicon: helpers.root('src', 'favicon.ico')
}),
// Copies all i18n files into dist/i18n
new CopyWebpackPlugin([{
from: helpers.root('src', 'i18n'),
to: 'i18n'
}]),
// Copies all lib files into dist/lib
new CopyWebpackPlugin([{
from: helpers.root('src', 'lib'),
to: 'lib'
}])
],
performance: {
hints: false
}
};
};
私はまだあなたがすべてのこれらのファイルを必要とするかわからないけどもしそうなら、ここに入れてください。ありがとうございました!
ご質問にapp.component.spec.tsを更新してください。 –
app.component.spec.tsが貼り付けた部分だけであるという表示を追加しました。私には行がありません。74:/ – Guigui