6

我正在尝试构建自己的 angular2/webpack2 样板,这是我的设置

webpack.common.js

const webpack = require('webpack');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const helpers = require('./helpers');

const METADATA = {
  title: 'Angular2 Webpack2 Starter by Whisher',
  baseUrl: '/',
  isDevServer: helpers.isWebpackDevServer()
};
module.exports = {
  devtool: 'cheap-module-source-map',
  entry: {
    'polyfills': './src/polyfills.ts',
    'vendor':    './src/vendor.ts',
    'main':      './src/main.ts'
  },
  resolve: {
    extensions: ['.ts', '.js', '.json']
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        loaders: [
          '@angularclass/hmr-loader',
          'awesome-typescript-loader',
          'angular2-template-loader',
          'angular-router-loader'
        ],
        exclude: [/\.(spec|e2e)\.ts$/]
      },
      {
        test: /\.html$/,
        loaders: ['html-loader']
      },
      {
        test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
        loader: 'file-loader?name=assets/[name].[hash].[ext]'
      },
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({
          fallbackLoader: 'style-loader',
          loader: 'css-loader?sourceMap'
        }),
        exclude: helpers.root('src', 'app'),
      },
      {
        test: /\.css$/,
        include: helpers.root('src', 'app'),
        loader: 'raw-loader'
      }
    ]
  },
  plugins: [
    new CommonsChunkPlugin({
      name: ['app', 'vendor', 'polyfills']
    }),
    new ExtractTextPlugin({ filename: 'bundle.css', disable: false, allChunks: true }),
    new HtmlWebpackPlugin({
      template: 'src/index.html',
      title: METADATA.title,
      metadata: METADATA,
      inject: 'body',
      hash: true
    }),
  ]
};

webpack.dev.js

const webpackMerge = require('webpack-merge');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const commonConfig = require('./webpack.common.js');

const helpers = require('./helpers');

module.exports = webpackMerge(commonConfig, {
  devtool: 'cheap-module-source-map',

  output: {
    path: helpers.root('dist'),
    filename: '[name].bundle.js',
    sourceMapFilename: '[name].map',
    chunkFilename: '[id].chunk.js'
  },

  plugins: [
    new ExtractTextPlugin('[name].css')
  ],

  devServer: {
    historyApiFallback: true,
    stats: 'minimal'
  }
});

该脚本工作正常,但我没有在运行时排除规范

npm 开始

我有

    WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
69:15-36 Critical dependency: the request of a dependency is an expression

WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
85:15-102 Critical dependency: the request of a dependency is an expression

ERROR in [at-loader] src/app/app.component.spec.ts:6:1 
    Cannot find name 'describe'.

ERROR in [at-loader] src/app/app.component.spec.ts:7:3 
    Cannot find name 'beforeEach'.

ERROR in [at-loader] src/app/app.component.spec.ts:15:3 
    Cannot find name 'it'.

ERROR in [at-loader] src/app/app.component.spec.ts:17:6 
    Cannot find name 'expect'.

ERROR in [at-loader] src/app/app.component.spec.ts:20:3 
    Cannot find name 'it'.

ERROR in [at-loader] src/app/app.component.spec.ts:24:5 
    Cannot find name 'expect'.

有什么问题 ?

提前致谢

回购协议

以防万一 https://bitbucket.org/whisher/angular2-webpack2-starter

解决了

在我的 tsconfig.json

"exclude": [
    "node_modules",
    "dist",
    "**/*.spec.ts"
  ],
4

0 回答 0