webpack 2 ts loader doesn't exclude spec file
Asked Answered
H

0

6

I'm trying to build my own angular2/webpack2 boilerplate this is my set up

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'
  }
});

The script works fine but I've not the spec excluded when I run

npm start

I've got

    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'.

What's the problem ?

Thanks in advance

REPO

just in case https://bitbucket.org/whisher/angular2-webpack2-starter

Worked out

In my tsconfig.json

"exclude": [
    "node_modules",
    "dist",
    "**/*.spec.ts"
  ],
Hirai answered 17/1, 2017 at 14:7 Comment(2)
Did you check this github.com/AngularClass/angular2-webpack-starter/issues/1371? There are a lot of rc version libraries in your package.json. So that is the main problem such errorsPulsate
@Whisher. You are awesome to put the "Worked out" and it really worked out for me :-)Ultramicroscope

© 2022 - 2024 — McMap. All rights reserved.