Add aspnet-webpack-react NPM package

This commit is contained in:
SteveSandersonMS
2016-03-10 23:21:16 +00:00
parent 2747aad66f
commit e5a6a05c97
9 changed files with 110 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
/typings/
/node_modules/
/*.js
/*.d.ts

View File

@@ -0,0 +1,3 @@
!/*.js
!/*.d.ts
/typings/

View File

@@ -0,0 +1,12 @@
Copyright (c) .NET Foundation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
these files except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -0,0 +1,6 @@
# Not for general use
This NPM package is an internal implementation detail of the `Microsoft.AspNet.SpaServices` NuGet package.
You should not use this package directly in your own applications, because it is not supported, and there are no
guarantees about how its APIs will change in the future.

View File

@@ -0,0 +1,21 @@
{
"name": "aspnet-webpack-react",
"version": "1.0.0",
"description": "Helpers for using Webpack with React in ASP.NET projects. Works in conjunction with the Microsoft.AspNet.SpaServices NuGet package.",
"main": "index.js",
"scripts": {
"prepublish": "tsd update && tsc && echo 'Finished building NPM package \"aspnet-webpack-react\"'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Microsoft",
"license": "Apache-2.0",
"dependencies": {
"babel-core": "^6.7.2",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"react": "^0.14.7",
"webpack": "^1.12.14"
}
}

View File

@@ -0,0 +1,33 @@
import * as webpack from 'webpack';
export function addReactHotModuleReplacementBabelTransform(webpackConfig: webpack.Configuration) {
webpackConfig.module.loaders.forEach(loaderConfig => {
if (loaderConfig.loader && loaderConfig.loader.match(/\bbabel-loader\b/)) {
// Ensure the babel-loader options includes a 'query'
const query = loaderConfig.query = loaderConfig.query || {};
// Ensure Babel plugins includes 'react-transform'
const plugins = query['plugins'] = query['plugins'] || [];
const hasReactTransform = plugins.some(p => p && p[0] === 'react-transform');
if (!hasReactTransform) {
plugins.push(['react-transform', {}]);
}
// Ensure 'react-transform' plugin is configured to use 'react-transform-hmr'
plugins.forEach(pluginConfig => {
if (pluginConfig && pluginConfig[0] === 'react-transform') {
const pluginOpts = pluginConfig[1] = pluginConfig[1] || {};
const transforms = pluginOpts.transforms = pluginOpts.transforms || [];
const hasReactTransformHmr = transforms.some(t => t.transform === 'react-transform-hmr');
if (!hasReactTransformHmr) {
transforms.push({
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module'] // Important for Webpack HMR
});
}
}
});
}
});
}

View File

@@ -0,0 +1 @@
export { addReactHotModuleReplacementBabelTransform } from './HotModuleReplacement';

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
"declaration": true,
"outDir": "."
},
"exclude": [
"node_modules"
]
}

View File

@@ -0,0 +1,18 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"source-map/source-map.d.ts": {
"commit": "0144ad5a74053f2292424847259c4c8e1d0fecaa"
},
"webpack/webpack.d.ts": {
"commit": "0144ad5a74053f2292424847259c4c8e1d0fecaa"
},
"uglify-js/uglify-js.d.ts": {
"commit": "0144ad5a74053f2292424847259c4c8e1d0fecaa"
}
}
}