Skip to content

Commit 5431abc

Browse files
TheLarkInnfilipesilva
authored andcommitted
chore(npm): updated webpack version and config cleanup (#2237)
* chore(npm): updated webpack version and reworked configs for breaking changes * fix: swapped enforce rules by accident, fix this * fix: fix version, as well as convert loaders to rules for future api changes * chore: update webpack to beta.24 * chore(npm): updated webpack to beta.25 * chore(lint): remove rogue double quote * Added augmented module typings for webpack v2 supporting webpack.LoaderOptionsPlugin * chore(lint): linting chores spaces, return lines, semis * chore(npm): updated both package.jsons cause who forgets to do that
1 parent b00ac7d commit 5431abc

7 files changed

+79
-60
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"typedoc": "^0.4.2",
111111
"typescript": "2.0.2",
112112
"url-loader": "^0.5.7",
113-
"webpack": "2.1.0-beta.22",
113+
"webpack": "2.1.0-beta.25",
114114
"webpack-dev-server": "2.1.0-beta.3",
115115
"webpack-md5-hash": "0.0.5",
116116
"webpack-merge": "^0.14.0",

packages/angular-cli/models/webpack-build-common.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export function getWebpackCommonConfig(
3333
return {
3434
devtool: 'source-map',
3535
resolve: {
36-
extensions: ['', '.ts', '.js'],
37-
root: appRoot
36+
extensions: ['.ts', '.js']
3837
},
3938
context: path.resolve(__dirname, './'),
4039
entry: entry,
@@ -43,18 +42,15 @@ export function getWebpackCommonConfig(
4342
filename: '[name].bundle.js'
4443
},
4544
module: {
46-
preLoaders: [
45+
rules: [
4746
{
47+
enforce: 'pre',
4848
test: /\.js$/,
4949
loader: 'source-map-loader',
5050
exclude: [
5151
/node_modules/
5252
]
53-
}
54-
],
55-
loaders: [
56-
// TypeScript loaders are separated into webpack-build-typescript.
57-
53+
},
5854
// in main, load css as raw text
5955
       {
6056
exclude: styles,
@@ -140,7 +136,7 @@ export function getWebpackCommonConfig(
140136
],
141137
node: {
142138
fs: 'empty',
143-
global: 'window',
139+
global: true,
144140
crypto: 'empty',
145141
module: false,
146142
clearImmediate: false,

packages/angular-cli/models/webpack-build-development.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
const path = require('path');
22

3+
import * as webpack from 'webpack';
4+
5+
declare module 'webpack' {
6+
export interface LoaderOptionsPlugin {}
7+
export interface LoaderOptionsPluginStatic {
8+
new (optionsObject: any): LoaderOptionsPlugin;
9+
}
10+
interface Webpack {
11+
LoaderOptionsPlugin: LoaderOptionsPluginStatic;
12+
}
13+
};
14+
315
export const getWebpackDevConfigPartial = function(projectRoot: string, appConfig: any) {
416
return {
517
devtool: 'source-map',
@@ -9,14 +21,20 @@ export const getWebpackDevConfigPartial = function(projectRoot: string, appConfi
921
sourceMapFilename: '[name].map',
1022
chunkFilename: '[id].chunk.js'
1123
},
12-
tslint: {
13-
emitErrors: false,
14-
failOnHint: false,
15-
resourcePath: path.resolve(projectRoot, appConfig.root)
16-
},
24+
plugins: [
25+
new webpack.LoaderOptionsPlugin({
26+
options: {
27+
tslint: {
28+
emitErrors: false,
29+
failOnHint: false,
30+
resourcePath: path.resolve(projectRoot, appConfig.root)
31+
},
32+
}
33+
})
34+
],
1735
node: {
1836
fs: 'empty',
19-
global: 'window',
37+
global: true,
2038
crypto: 'empty',
2139
process: true,
2240
module: false,

packages/angular-cli/models/webpack-build-production.ts

+21-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as webpack from 'webpack';
55

66
export const getWebpackProdConfigPartial = function(projectRoot: string, appConfig: any) {
77
return {
8-
debug: false,
98
devtool: 'source-map',
109
output: {
1110
path: path.resolve(projectRoot, appConfig.outDir),
@@ -25,27 +24,31 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf
2524
test: /\.js$|\.html$/,
2625
threshold: 10240,
2726
minRatio: 0.8
27+
}),
28+
new webpack.LoaderOptionsPlugin({
29+
options: {
30+
tslint: {
31+
emitErrors: true,
32+
failOnHint: true,
33+
resourcePath: path.resolve(projectRoot, appConfig.root)
34+
},
35+
htmlLoader: {
36+
minimize: true,
37+
removeAttributeQuotes: false,
38+
caseSensitive: true,
39+
customAttrSurround: [
40+
[/#/, /(?:)/],
41+
[/\*/, /(?:)/],
42+
[/\[?\(?/, /(?:)/]
43+
],
44+
customAttrAssign: [/\)?\]?=/]
45+
}
46+
}
2847
})
2948
],
30-
tslint: {
31-
emitErrors: true,
32-
failOnHint: true,
33-
resourcePath: path.resolve(projectRoot, appConfig.root)
34-
},
35-
htmlLoader: {
36-
minimize: true,
37-
removeAttributeQuotes: false,
38-
caseSensitive: true,
39-
customAttrSurround: [
40-
[/#/, /(?:)/],
41-
[/\*/, /(?:)/],
42-
[/\[?\(?/, /(?:)/]
43-
],
44-
customAttrAssign: [/\)?\]?=/]
45-
},
4649
node: {
4750
fs: 'empty',
48-
global: 'window',
51+
global: true,
4952
crypto: 'empty',
5053
process: true,
5154
module: false,

packages/angular-cli/models/webpack-build-test.js

+25-23
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
1111
devtool: 'inline-source-map',
1212
context: path.resolve(__dirname, './'),
1313
resolve: {
14-
extensions: ['', '.ts', '.js'],
15-
root: appRoot
14+
extensions: ['.ts', '.js']
1615
},
1716
entry: {
1817
test: path.resolve(appRoot, appConfig.test)
@@ -22,24 +21,24 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
2221
filename: '[name].bundle.js'
2322
},
2423
module: {
25-
preLoaders: [
24+
rules: [
2625
{
2726
test: /\.ts$/,
27+
enforce: 'pre',
2828
loader: 'tslint-loader',
2929
exclude: [
3030
path.resolve(projectRoot, 'node_modules')
3131
]
3232
},
3333
{
3434
test: /\.js$/,
35+
enforce: 'pre',
3536
loader: 'source-map-loader',
3637
exclude: [
3738
path.resolve(projectRoot, 'node_modules/rxjs'),
3839
path.resolve(projectRoot, 'node_modules/@angular')
3940
]
40-
}
41-
],
42-
loaders: [
41+
},
4342
{
4443
test: /\.ts$/,
4544
loaders: [
@@ -58,23 +57,22 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
5857
],
5958
exclude: [/\.e2e\.ts$/]
6059
},
61-
{ test: /\.json$/, loader: 'json-loader' },
62-
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
63-
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
64-
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
65-
{ test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
66-
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' },
67-
{ test: /\.html$/, loader: 'raw-loader', exclude: [path.resolve(appRoot, appConfig.index)] }
68-
],
69-
postLoaders: [
7060
{
7161
test: /\.(js|ts)$/, loader: 'sourcemap-istanbul-instrumenter-loader',
62+
enforce: 'post',
7263
exclude: [
7364
/\.(e2e|spec)\.ts$/,
7465
/node_modules/
7566
],
7667
query: { 'force-sourcemap': true }
77-
}
68+
},
69+
{ test: /\.json$/, loader: 'json-loader' },
70+
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
71+
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
72+
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
73+
{ test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
74+
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' },
75+
{ test: /\.html$/, loader: 'raw-loader', exclude: [path.resolve(appRoot, appConfig.index)] }
7876
]
7977
},
8078
plugins: [
@@ -89,16 +87,20 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
8987
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
9088
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
9189
path.resolve(appRoot, appConfig.environments[environment])
92-
)
90+
),
91+
new webpack.LoaderOptionsPlugin({
92+
options: {
93+
tslint: {
94+
emitErrors: false,
95+
failOnHint: false,
96+
resourcePath: `./${appConfig.root}`
97+
}
98+
}
99+
})
93100
],
94-
tslint: {
95-
emitErrors: false,
96-
failOnHint: false,
97-
resourcePath: `./${appConfig.root}`
98-
},
99101
node: {
100102
fs: 'empty',
101-
global: 'window',
103+
global: true,
102104
process: false,
103105
crypto: 'empty',
104106
module: false,

packages/angular-cli/models/webpack-build-typescript.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo
1717

1818
return {
1919
module: {
20-
loaders: [
20+
rules: [
2121
{
2222
test: /\.ts$/,
2323
loaders: [{
@@ -43,7 +43,7 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo
4343
export const getWebpackAotConfigPartial = function(projectRoot: string, appConfig: any) {
4444
return {
4545
module: {
46-
loaders: [
46+
rules: [
4747
{
4848
test: /\.ts$/,
4949
loader: webpackLoader,

packages/angular-cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"typedoc": "^0.4.2",
9494
"typescript": "2.0.2",
9595
"url-loader": "^0.5.7",
96-
"webpack": "2.1.0-beta.22",
96+
"webpack": "2.1.0-beta.25",
9797
"webpack-dev-server": "2.1.0-beta.3",
9898
"webpack-md5-hash": "0.0.5",
9999
"webpack-merge": "^0.14.0",

0 commit comments

Comments
 (0)