diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/.gitignore b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/.gitignore new file mode 100644 index 0000000000..a1df9a5c2b --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/.gitignore @@ -0,0 +1,4 @@ +/typings/ +/node_modules/ +/*.js +/*.d.ts diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/.npmignore b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/.npmignore new file mode 100644 index 0000000000..858cdc4c3b --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/.npmignore @@ -0,0 +1,3 @@ +!/*.js +!/*.d.ts +/typings/ diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/LICENSE.txt b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/LICENSE.txt new file mode 100644 index 0000000000..0bdc1962b6 --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/LICENSE.txt @@ -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. diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/README.md b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/README.md new file mode 100644 index 0000000000..e459de765e --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/README.md @@ -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. diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/package.json b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/package.json new file mode 100644 index 0000000000..8d88e0422d --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/package.json @@ -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" + } +} diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/src/HotModuleReplacement.ts b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/src/HotModuleReplacement.ts new file mode 100644 index 0000000000..4756e4cd92 --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/src/HotModuleReplacement.ts @@ -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 + }); + } + } + }); + } + }); +} diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/src/index.ts b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/src/index.ts new file mode 100644 index 0000000000..34dab6025b --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/src/index.ts @@ -0,0 +1 @@ +export { addReactHotModuleReplacementBabelTransform } from './HotModuleReplacement'; diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/tsconfig.json b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/tsconfig.json new file mode 100644 index 0000000000..de676e91e5 --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "module": "commonjs", + "target": "es5", + "declaration": true, + "outDir": "." + }, + "exclude": [ + "node_modules" + ] +} diff --git a/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/tsd.json b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/tsd.json new file mode 100644 index 0000000000..e9e4f33c94 --- /dev/null +++ b/src/Microsoft.AspNet.SpaServices/npm/aspnet-webpack-react/tsd.json @@ -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" + } + } +}