Skip to content
This repository was archived by the owner on Apr 28, 2021. It is now read-only.

Commit bd31ffe

Browse files
committed
Upgrade to Webpack2.
Also switches TypeScript to emit ES2015 modules instead of CommonJS so we can take advantage of tree shaking to reduce bundle sizes. The gains here are barely noticeable though (there's an outstanding issue with how TypeScript emits classes and how Uglify interacts with that that may help once that's fixed), but every little bit helps. mishoo/UglifyJS#1261 microsoft/TypeScript#13721 webpack/webpack#2899 TODO: Look to see if we can convert more of our more imports to ES2015 to impove tree shaking.
1 parent c69d9c9 commit bd31ffe

File tree

6 files changed

+96
-63
lines changed

6 files changed

+96
-63
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,31 @@
2525
"autoprefixer": "^6.6.1",
2626
"chai": "^3.5.0",
2727
"copy-webpack-plugin": "^4.0.1",
28-
"css-loader": "^0.23.1",
28+
"css-loader": "^0.26.2",
2929
"enzyme": "^2.7.0",
30-
"extract-text-webpack-plugin": "^1.0.1",
30+
"extract-text-webpack-plugin": "^2.1.0",
3131
"file-loader": "^0.9.0",
3232
"jsdom": "^9.9.1",
3333
"json-loader": "^0.5.4",
3434
"less": "^2.7.2",
3535
"less-loader": "^2.2.3",
3636
"mime": "^1.3.4",
3737
"mocha": "^2.5.3",
38-
"nunjucks-html-loader": "^1.0.0",
38+
"nunjucks-html-loader": "^1.1.0",
3939
"postcss-loader": "^0.9.1",
4040
"react-addons-test-utils": "^15.3.2",
4141
"sinon": "^1.17.7",
4242
"source-map-loader": "^0.1.5",
43-
"style-loader": "^0.13.1",
43+
"style-loader": "^0.13.2",
4444
"sync-exec": "^0.6.2",
45-
"ts-loader": "^1.3.2",
46-
"ts-node": "^2.0.0",
45+
"ts-loader": "^2.0.1",
46+
"ts-node": "^2.1.0",
4747
"typescript": "^2.2.1",
4848
"util-inspect": "^0.1.8",
49-
"webpack": "^1.13.1",
50-
"webpack-dev-server": "^1.14.1",
49+
"webpack": "^2.2.1",
50+
"webpack-dev-server": "^2.4.1",
5151
"webpack-path-rewriter": "^1.1.4",
52-
"worker-loader": "^0.7.1"
52+
"worker-loader": "^0.8.0"
5353
},
5454
"dependencies": {
5555
"autoprefixer": "^6.7.6",

test-helpers/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ function createDOM() {
3333
} as any;
3434
}
3535

36-
export = createDOM();
36+
export default createDOM();

ts/components/Waypoint.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/*
22
Wraps react-waypoint module in proper ES6 form
33
*/
4-
import Waypoint = require('react-waypoint');
4+
5+
// Technically incorrect per ES6 standard but builds with Webpack transpiler
6+
import * as Waypoint from 'react-waypoint';
7+
58
export default Waypoint;

ts/tasks/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"noFallthroughCasesInSwitch": true,
1212
"noUnusedLocals": true,
1313
"strictNullChecks": true,
14-
"module": "commonjs",
14+
"module": "es2015",
15+
"moduleResolution": "node",
1516
"target": "es5",
1617
"typeRoots" : ["../../typings", "../../node_modules/@types"],
1718
"jsx": "react",

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"noFallthroughCasesInSwitch": true,
1212
"noUnusedLocals": true,
1313
"strictNullChecks": true,
14-
"module": "commonjs",
14+
"module": "es2015",
15+
"moduleResolution": "node",
1516
"target": "es5",
1617
"typeRoots" : ["./typings", "./node_modules/@types"],
1718
"jsx": "react",

webpack.config.js

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var config = {
6363

6464
resolve: {
6565
// Add '.ts' and '.tsx' as resolvable extensions.
66-
extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".json"],
66+
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
6767

6868
alias: {
6969
// Special config path based on environment
@@ -72,13 +72,13 @@ var config = {
7272
},
7373

7474
module: {
75-
loaders: [
75+
rules: [
7676
{ test: /\.html?$/,
7777
loader: PathRewriterPlugin.rewriteAndEmit({
7878
name: "[path][name]",
7979
context: "html",
8080
includeHash: true,
81-
loader: 'nunjucks-html?' + JSON.stringify({
81+
loader: 'nunjucks-html-loader?' + JSON.stringify({
8282
searchPaths: [ path.join(__dirname, "html") ],
8383

8484
// Nunjucks / Jinja context
@@ -90,46 +90,66 @@ var config = {
9090
})
9191
},
9292

93-
{ test: /\.less?$/,
94-
loader: ExtractTextPlugin.extract("style-loader",
95-
"css?" + (prodLike ? "minimize" : "") + "sourceMap" +
96-
"!postcss?sourceMap" +
97-
"!less?sourceMap"
98-
)
99-
},
100-
101-
{ test: /\.css?$/,
102-
loader: ExtractTextPlugin.extract("style-loader",
103-
"css?" + (prodLike ? "minimize" : "") + "sourceMap" +
104-
"!postcss?sourceMap"
105-
)
106-
},
107-
108-
{ test: /\.tsx?$/,
109-
loader: "ts-loader",
110-
exclude: [/\.(test)\.tsx?$/] },
111-
112-
{ test: /\.json$/, loader: "json-loader" },
93+
// CSS / LESS
94+
{ test: /(\.css|\.less)$/,
95+
loader: ExtractTextPlugin.extract({
96+
fallback: "style-loader",
97+
use: [{
98+
loader: "css-loader",
99+
options: {
100+
minimize: prodLike,
101+
sourceMap: true
102+
}
103+
}, {
104+
loader: 'postcss-loader',
105+
options: {
106+
plugins: function () { return [autoprefixer({
107+
browsers: ['last 3 versions']
108+
})]; },
109+
sourceMap: true
110+
}
111+
}, {
112+
loader: 'less-loader',
113+
options: { sourceMap: true }
114+
}]
115+
}) },
116+
117+
// TypeScript
118+
{ test: /\.ts(x?)$/,
119+
exclude: /node_modules/,
120+
use: [{
121+
loader: 'ts-loader',
122+
options: { sourceMap: true }
123+
}] },
113124

114125
// Static assets
115126
{ test: /.*/,
116-
loader: "file?context=assets&name=[path][name].[ext]",
127+
use: [{
128+
loader: 'file-loader',
129+
options: {
130+
context: "assets",
131+
name: "[path][name].[ext]"
132+
}
133+
}],
117134
include: [ path.resolve(__dirname, "./assets") ]
118135
// exclude: /\.html$/
119136
},
120137

121138
{ test: /\.(woff|woff2|eot|ttf|svg)(\?.*)?$/,
122-
loader: "file?context=node_modules&name=fonts/[name].[ext]",
139+
use: [{
140+
loader: 'file-loader',
141+
options: {
142+
context: "node_modules",
143+
name: "fonts/[name].[ext]"
144+
}
145+
}],
123146
include: [ path.resolve(__dirname, "./node_modules") ]
124-
}
125-
],
147+
},
126148

127-
preLoaders: [
128-
/*
129-
All output '.js' files will have any sourcemaps re-processed by
130-
'source-map-loader'.
131-
*/
132-
{ test: /\.js$/, loader: "source-map-loader" }
149+
// Source map extraction
150+
{ test: /\.js$/,
151+
use: ["source-map-loader"],
152+
enforce: "pre" }
133153
]
134154
},
135155

@@ -147,35 +167,40 @@ var config = {
147167
}
148168
}),
149169

150-
new ExtractTextPlugin(
151-
"css/[name]--" + (prodLike ? "[contenthash]" : "dev") + ".css",
152-
{ allChunks: true }),
170+
new ExtractTextPlugin({
171+
filename: "css/[name]--" + (prodLike ? "[contenthash]" : "dev") + ".css",
172+
allChunks: true
173+
}),
174+
153175
new webpack.optimize.CommonsChunkPlugin({
154176
name: "vendor",
155177
filename: "js/[name]--" + (prodLike ? "[chunkhash]" : "dev") + ".js"
156178
}),
179+
157180
new PathRewriterPlugin()
158181
],
159182

160-
postcss: function () {
161-
return [autoprefixer({
162-
browsers: ['last 3 versions']
163-
})];
164-
},
165-
166183
devServer: {
167184
historyApiFallback: true
168-
},
185+
}
186+
};
169187

170-
worker: {
171-
output: {
172-
filename: "js/[name].worker--" +
173-
(prodLike ? "[chunkhash]" : "dev") + ".js",
174-
chunkFilename: "js/[name].worker--" +
175-
(prodLike ? "[chunkhash]" : "dev") + ".js"
188+
// Back-compat config
189+
config.plugins.push(new webpack.LoaderOptionsPlugin({
190+
options: {
191+
context: '/',
192+
output: config.output,
193+
worker: {
194+
output: {
195+
filename: "js/[name].worker--" +
196+
(prodLike ? "[chunkhash]" : "dev") + ".js",
197+
chunkFilename: "js/[name].worker--" +
198+
(prodLike ? "[chunkhash]" : "dev") + ".js"
199+
}
176200
}
177201
}
178-
};
202+
}));
203+
179204

180205
if (! prodLike) {
181206
/*
@@ -194,6 +219,9 @@ if (! prodLike) {
194219

195220
if (prodLike) {
196221
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
222+
screw_ie8: true,
223+
sourceMap: true,
224+
197225
// Disable warnings about un-reachable conditions and what not. Most
198226
// of those are intentional (e.g. via webpack.DefinePlugin)
199227
compress: {warnings: false}

0 commit comments

Comments
 (0)