Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Commit

Permalink
feat(webpack): Use newer webpack config style
Browse files Browse the repository at this point in the history
see #23
hypery2k committed Jan 19, 2017
1 parent 02c1162 commit 8f9fbfa
Showing 6 changed files with 50 additions and 137 deletions.
10 changes: 7 additions & 3 deletions etc/appConfig.js
Original file line number Diff line number Diff line change
@@ -17,9 +17,13 @@ var appConfig = {
chunks: {
name: ['polyfills', 'vendor'].reverse()
},
srcSASS: path.resolve(sourceRoot, 'scss'),
srcI18N: path.resolve(sourceRoot, 'app', 'i18n'),
srcIMG: path.resolve(sourceRoot, 'img'),
copy: [{
from: path.resolve(sourceRoot, 'img'),
to: 'img'
}, {
from: path.resolve(sourceRoot, 'i18n'),
to: 'i18n'
}],
indexFiles: [{
chunks: ['main', 'polyfills', 'vendor'],
template: path.resolve(sourceRoot, 'index.html'),
95 changes: 29 additions & 66 deletions etc/webpack.common.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@ const webpack = require('webpack');
/*
* Webpack Plugins
*/
const {TsConfigPathsPlugin, CheckerPlugin} = require('awesome-typescript-loader');
const CheckerPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
const TsConfigPathsPlugin = require('awesome-typescript-loader').CheckerPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
@@ -48,13 +49,6 @@ var config = {
warnings: false,
publicPath: false
},
/*
* Static metadata for index.html
*
* See: (custom attribute)
*/
metadata: METADATA,


/*
* The entry point for the bundle
@@ -76,22 +70,13 @@ var config = {
*
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
*/
extensions: ['', '.ts', '.js', '.json'],
extensions: ['.ts', '.js', '.json'],

// Make sure root is src
root: appConfig.src,

// remove other default values
modulesDirectories: ['node_modules']

},

htmlLoader: {
minimize: true,
removeAttributeQuotes: false,
caseSensitive: true,
customAttrSurround: [[/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/]],
customAttrAssign: [/\)?\]?=/]
modules: [
appConfig.src,
'node_modules'
]
},

/*
@@ -104,12 +89,20 @@ var config = {
// resolve https://github.com/holisticon/angular-common/issues/10
exprContextCritical: false,

noParse: [
/angular2|zone.js/
],

/*
* An array of applied pre and post loaders.
* An array of automatically applied loaders.
*
* IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
* This means they are not resolved relative to the configuration file.
*
* See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
* See: http://webpack.github.io/docs/configuration.html#module-loaders
*/
preLoaders: [
rules: [
// PRE-LOADERS
{
test: /\.ts$/,
loader: 'string-replace-loader',
@@ -118,7 +111,8 @@ var config = {
replace: '$1.import($3).then(mod => (mod.__esModule && mod.default) ? mod.default : mod)',
flags: 'g'
},
include: [helpers.root('src')]
include: [helpers.root('src')],
enforce: 'pre'
},

/*
@@ -132,7 +126,8 @@ var config = {
exclude: [
/node_modules/,
/\.(html|css|sass)$/
]
],
enforce: 'pre'
},

/*
@@ -150,25 +145,10 @@ var config = {
helpers.root('node_modules/@angular'),
helpers.root('node_modules/@ngrx'),
helpers.root('node_modules/@angular2-material')
]
}

],
noParse: [
path.join(__dirname, 'node_modules', 'zone.js', 'dist'),
path.join(__dirname, 'node_modules', 'angular2', 'bundles')
],

/*
* An array of automatically applied loaders.
*
* IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
* This means they are not resolved relative to the configuration file.
*
* See: http://webpack.github.io/docs/configuration.html#module-loaders
*/
loaders: [

],
enforce: 'pre'
},
// LOADERS
/*
* Typescript loader support for .ts and Angular 2 async routes via .async.ts
*
@@ -179,20 +159,12 @@ var config = {
test: /\.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
},
/*
* Json loader support for *.json files.
*
* See: https://github.com/webpack/json-loader
*/
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
},
// https://github.com/jtangelder/sass-loader#usage
// TODO appConfig.srcSASS
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
@@ -221,9 +193,6 @@ var config = {
]

},
sassLoader: {
includePaths: [appConfig.srcSASS]
},

/*
* Add additional plugins to the compiler.
@@ -265,13 +234,7 @@ var config = {
*
* See: https://www.npmjs.com/package/copy-webpack-plugin
*/
new CopyWebpackPlugin([{
from: appConfig.srcIMG,
to: 'img'
}, {
from: appConfig.srcI18N,
to: 'i18n'
}]),
new CopyWebpackPlugin(appConfig.copy),
/**
* Plugin: DefinePlugin
* Description: Define free variables.
@@ -300,7 +263,7 @@ var config = {
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: 'window',
global: true,
crypto: 'empty',
module: false,
clearImmediate: false,
63 changes: 6 additions & 57 deletions etc/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ const commonConfig = require('./webpack.common.js'); // the settings that are co
/**
* Webpack Plugins
*/
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const ProvidePlugin = webpack.ProvidePlugin;
const DefinePlugin = webpack.DefinePlugin;
const NormalModuleReplacementPlugin = webpack.NormalModuleReplacementPlugin;
@@ -35,13 +35,6 @@ const METADATA = webpackMerge(commonConfig.metadata, {

module.exports = webpackMerge(commonConfig, {

/**
* Switch loaders to debug mode.
*
* See: http://webpack.github.io/docs/configuration.html#debug
*/
debug: false,

/**
* Options affecting the output of the compilation.
*
@@ -100,12 +93,13 @@ module.exports = webpackMerge(commonConfig, {
new webpack.optimize.CommonsChunkPlugin(appConfig.chunks),

/*
* Plugin: ForkCheckerPlugin
* Plugin: CheckerPlugin
* Description: Do type checking in a separate process, so webpack don't need to wait.
*
* See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
* See: https://github.com/s-panferov/awesome-typescript-loader#configuration
*/
new ForkCheckerPlugin(),
new CheckerPlugin(),


/**
* Plugin: WebpackMd5Hash
@@ -219,51 +213,6 @@ module.exports = webpackMerge(commonConfig, {
// threshold: 2 * 1024
// })

],

/**
* Static analysis linter for TypeScript advanced options configuration
* Description: An extensible linter for the TypeScript language.
*
* See: https://github.com/wbuchwalter/tslint-loader
*/
tslint: {
emitErrors: true,
failOnHint: true,
resourcePath: appConfig.srcApp
},

/**
* Html loader advanced options
*
* See: https://github.com/webpack/html-loader#advanced-options
*/
// TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
htmlLoader: {
minimize: true,
removeAttributeQuotes: false,
caseSensitive: true,
customAttrSurround: [
[/#/, /(?:)/],
[/\*/, /(?:)/],
[/\[?\(?/, /(?:)/]
],
customAttrAssign: [/\)?\]?=/]
},

/*
* Include polyfills or mocks for various node stuff
* Description: Node configuration
*
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: 'window',
crypto: 'empty',
process: false,
module: false,
clearImmediate: false,
setImmediate: false
}
]

});
12 changes: 4 additions & 8 deletions etc/webpack.test.js
Original file line number Diff line number Diff line change
@@ -43,13 +43,8 @@ module.exports = webpackMerge(commonConfig, {
* See: http://webpack.github.io/docs/configuration.html#module
*/
module: {

/**
* An array of applied pre and post loaders.
*
* See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
*/
postLoaders: [
rules: [
// POST-LOADERS

/**
* Instruments JS files with Istanbul for subsequent code coverage reporting.
@@ -67,7 +62,8 @@ module.exports = webpackMerge(commonConfig, {
exclude: [
/\.(e2e|spec)\.ts$/,
/node_modules/
]
],
enforce: 'post'
}

]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
"babel-plugin-transform-es2015-constants": "6.1.4",
"babel-polyfill": "6.16.0",
"babel-preset-es2015": "6.16.0",
"codelyzer": "0.0.28",
"codelyzer": "1.0.0-beta.4",
"concurrently": "3.1.0",
"copy-webpack-plugin": "4.0.1",
"core-js": "2.4.1",
@@ -79,9 +79,9 @@
"to-string-loader": "1.1.5",
"ts-helpers": "1.1.1",
"ts-node": "1.4.1",
"tslint": "3.15.1",
"tslint": "4.3.1",
"tslint-eslint-rules": "2.1.0",
"tslint-loader": "3.3.0",
"tslint-loader": "3.2.1",
"typedoc": "0.4.5",
"typescript": "2.0.3",
"typings": "1.4.0",
1 change: 1 addition & 0 deletions test/appConfigTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var appConfig = {
srcPath: 'app',
genPath: 'src-gen',
copy: [],
testPath: 'specs', junit: {
name: 'Holisticon-TestApp',
dir: '../target/test-reports'

0 comments on commit 8f9fbfa

Please sign in to comment.