Skip to content

Commit e5a6a05

Browse files
Add aspnet-webpack-react NPM package
1 parent 2747aad commit e5a6a05

9 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/typings/
2+
/node_modules/
3+
/*.js
4+
/*.d.ts
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!/*.js
2+
!/*.d.ts
3+
/typings/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright (c) .NET Foundation. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
these files except in compliance with the License. You may obtain a copy of the
5+
License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software distributed
10+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
specific language governing permissions and limitations under the License.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Not for general use
2+
3+
This NPM package is an internal implementation detail of the `Microsoft.AspNet.SpaServices` NuGet package.
4+
5+
You should not use this package directly in your own applications, because it is not supported, and there are no
6+
guarantees about how its APIs will change in the future.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "aspnet-webpack-react",
3+
"version": "1.0.0",
4+
"description": "Helpers for using Webpack with React in ASP.NET projects. Works in conjunction with the Microsoft.AspNet.SpaServices NuGet package.",
5+
"main": "index.js",
6+
"scripts": {
7+
"prepublish": "tsd update && tsc && echo 'Finished building NPM package \"aspnet-webpack-react\"'",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "Microsoft",
11+
"license": "Apache-2.0",
12+
"dependencies": {
13+
"babel-core": "^6.7.2",
14+
"babel-loader": "^6.2.4",
15+
"babel-plugin-react-transform": "^2.0.2",
16+
"babel-preset-es2015": "^6.6.0",
17+
"babel-preset-react": "^6.5.0",
18+
"react": "^0.14.7",
19+
"webpack": "^1.12.14"
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as webpack from 'webpack';
2+
3+
export function addReactHotModuleReplacementBabelTransform(webpackConfig: webpack.Configuration) {
4+
webpackConfig.module.loaders.forEach(loaderConfig => {
5+
if (loaderConfig.loader && loaderConfig.loader.match(/\bbabel-loader\b/)) {
6+
// Ensure the babel-loader options includes a 'query'
7+
const query = loaderConfig.query = loaderConfig.query || {};
8+
9+
// Ensure Babel plugins includes 'react-transform'
10+
const plugins = query['plugins'] = query['plugins'] || [];
11+
const hasReactTransform = plugins.some(p => p && p[0] === 'react-transform');
12+
if (!hasReactTransform) {
13+
plugins.push(['react-transform', {}]);
14+
}
15+
16+
// Ensure 'react-transform' plugin is configured to use 'react-transform-hmr'
17+
plugins.forEach(pluginConfig => {
18+
if (pluginConfig && pluginConfig[0] === 'react-transform') {
19+
const pluginOpts = pluginConfig[1] = pluginConfig[1] || {};
20+
const transforms = pluginOpts.transforms = pluginOpts.transforms || [];
21+
const hasReactTransformHmr = transforms.some(t => t.transform === 'react-transform-hmr');
22+
if (!hasReactTransformHmr) {
23+
transforms.push({
24+
transform: 'react-transform-hmr',
25+
imports: ['react'],
26+
locals: ['module'] // Important for Webpack HMR
27+
});
28+
}
29+
}
30+
});
31+
}
32+
});
33+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { addReactHotModuleReplacementBabelTransform } from './HotModuleReplacement';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"moduleResolution": "node",
4+
"module": "commonjs",
5+
"target": "es5",
6+
"declaration": true,
7+
"outDir": "."
8+
},
9+
"exclude": [
10+
"node_modules"
11+
]
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": "v4",
3+
"repo": "borisyankov/DefinitelyTyped",
4+
"ref": "master",
5+
"path": "typings",
6+
"bundle": "typings/tsd.d.ts",
7+
"installed": {
8+
"source-map/source-map.d.ts": {
9+
"commit": "0144ad5a74053f2292424847259c4c8e1d0fecaa"
10+
},
11+
"webpack/webpack.d.ts": {
12+
"commit": "0144ad5a74053f2292424847259c4c8e1d0fecaa"
13+
},
14+
"uglify-js/uglify-js.d.ts": {
15+
"commit": "0144ad5a74053f2292424847259c4c8e1d0fecaa"
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)