@ -1,5 +1,5 @@
const webpack = require ( 'webpack' ) ,
const webpack = require ( 'webpack' ) ,
path = require ( 'path' ) ;
path = require ( 'path' ) ;
const appRoot = path . resolve ( __ dirname , '..' ) ;
const appRoot = path . resolve ( __ dirname , '..' ) ;
@ -28,12 +28,12 @@ const plugins = {
TsLintPlugin : require ( 'tslint-webpack-plugin' )
TsLintPlugin : require ( 'tslint-webpack-plugin' )
} ;
} ;
module . exports = function ( env ) {
module . exports = function ( env ) {
const isDevServer = path . basename ( require . main . filename ) === 'webpack-dev-server.js' ;
const isDevServer = path . basename ( require . main . filename ) === 'webpack-dev-server.js' ;
const isProduction = env && env . production ;
const isProduction = env && env . production ;
const isTests = env && env . target === 'tests' ;
const isTests = env && env . target === 'tests' ;
const isCoverage = env && env . coverage ;
const isCoverage = env && env . coverage ;
const isJit = env && env . jit ;
const isAot = isProduction ;
const config = {
const config = {
mode : isProduction ? 'production' : 'development' ,
mode : isProduction ? 'production' : 'development' ,
@ -56,7 +56,7 @@ module.exports = function(env) {
*
*
* See : https : //webpack.js.org/configuration/resolve/#resolve-extensions
* See : https : //webpack.js.org/configuration/resolve/#resolve-extensions
* /
* /
extensions : [ '.js' , '.mjs' , '.t s' , '.css' , '.scss' ] ,
extensions : [ '.ts' , '. js' , '.mjs' , '.css' , '.scss' ] ,
modules : [
modules : [
root ( 'app' ) ,
root ( 'app' ) ,
root ( 'app' , 'theme' ) ,
root ( 'app' , 'theme' ) ,
@ -122,9 +122,9 @@ module.exports = function(env) {
test : /\.css$/ ,
test : /\.css$/ ,
use : [
use : [
plugins . MiniCssExtractPlugin . loader ,
plugins . MiniCssExtractPlugin . loader ,
{
{
loader : 'css-loader'
loader : 'css-loader'
} ]
} ]
} , {
} , {
test : /\.scss$/ ,
test : /\.scss$/ ,
use : [ {
use : [ {
@ -181,8 +181,6 @@ module.exports = function(env) {
}
}
} ;
} ;
console . log ( JSON . stringify ( config , null , 2 ) ) ;
if ( ! isTests ) {
if ( ! isTests ) {
/ * *
/ * *
* The entry point for the bundle . Our Angular app .
* The entry point for the bundle . Our Angular app .
@ -258,6 +256,15 @@ module.exports = function(env) {
waitForLinting : isProduction
waitForLinting : isProduction
} )
} )
) ;
) ;
config . plugins . push (
new plugins . NgToolsWebpack . AngularCompilerPlugin ( {
entryModule : 'app/app.module#AppModule' ,
sourceMap : ! isProduction ,
skipSourceGeneration : ! isAot ,
tsConfigPath : './tsconfig.json'
} )
) ;
}
}
if ( isProduction ) {
if ( isProduction ) {
@ -284,14 +291,8 @@ module.exports = function(env) {
} ;
} ;
}
}
if ( ! isCoverage ) {
if ( isCoverage ) {
config . module . rules . push ( {
// Do not instrument tests.
test : /\.ts$/ ,
use : [ {
loader : 'awesome-typescript-loader' , options : { useCache : true , useBabel : true }
} ]
} )
} else {
config . module . rules . push ( {
config . module . rules . push ( {
test : /\.ts$/ ,
test : /\.ts$/ ,
use : [ {
use : [ {
@ -300,7 +301,7 @@ module.exports = function(env) {
include : [ /\.(e2e|spec)\.ts$/ ] ,
include : [ /\.(e2e|spec)\.ts$/ ] ,
} ) ;
} ) ;
// Use instrument loader for all normal build s.
// Use instrument loader for all normal file s.
config . module . rules . push ( {
config . module . rules . push ( {
test : /\.ts$/ ,
test : /\.ts$/ ,
use : [ {
use : [ {
@ -310,6 +311,13 @@ module.exports = function(env) {
} ] ,
} ] ,
exclude : [ /\.(e2e|spec)\.ts$/ ]
exclude : [ /\.(e2e|spec)\.ts$/ ]
} ) ;
} ) ;
} else {
config . module . rules . push ( {
test : /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/ ,
use : [ {
loader : plugins . NgToolsWebpack . NgToolsLoader
} ]
} )
}
}
if ( isProduction ) {
if ( isProduction ) {
@ -322,11 +330,11 @@ module.exports = function(env) {
* /
* /
use : [
use : [
plugins . MiniCssExtractPlugin . loader ,
plugins . MiniCssExtractPlugin . loader ,
{
{
loader : 'css-loader'
loader : 'css-loader'
} , {
} , {
loader : 'sass-loader'
loader : 'sass-loader'
} ] ,
} ] ,
/ *
/ *
* Do not include component styles .
* Do not include component styles .
* /
* /
@ -349,23 +357,5 @@ module.exports = function(env) {
} ) ;
} ) ;
}
}
if ( ! isJit ) {
config . module . rules . push ( {
test : /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/ ,
use : [ {
loader : '@ngtools/webpack'
} ]
} ) ;
config . plugins . push (
new plugins . NgToolsWebpack . AngularCompilerPlugin ( {
entryModule : 'app/app.module#AppModule' ,
sourceMap : ! isProduction ,
skipSourceGeneration : false ,
tsConfigPath : './tsconfig.json'
} )
) ;
}
return config ;
return config ;
} ;
} ;