Build SpaServices 'Node/Content/*.js' files from TypeScript sources

This commit is contained in:
SteveSandersonMS
2016-11-25 15:06:23 +00:00
parent dd97ae7316
commit 9f6b0b0573
10 changed files with 274 additions and 38 deletions

View File

@@ -44,5 +44,11 @@
"embed": [ "embed": [
"Content/**/*" "Content/**/*"
] ]
},
"scripts": {
"prepublish": [
"npm install",
"node node_modules/webpack/bin/webpack.js"
]
} }
} }

View File

@@ -1 +1,2 @@
/bin/ /bin/
/node_modules/

View File

@@ -1,20 +1,83 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
// Pass through the invocation to the 'aspnet-prerendering' package, verifying that it can be loaded // Pass through the invocation to the 'aspnet-prerendering' package, verifying that it can be loaded
module.exports.renderToString = function (callback) { function renderToString(callback) {
var aspNetPrerendering; var aspNetPrerendering;
try { try {
aspNetPrerendering = require('aspnet-prerendering'); aspNetPrerendering = __webpack_require__(2);
} catch (ex) { }
catch (ex) {
// Developers sometimes have trouble with badly-configured Node installations, where it's unable // Developers sometimes have trouble with badly-configured Node installations, where it's unable
// to find node_modules. Or they accidentally fail to deploy node_modules, or even to run 'npm install'. // to find node_modules. Or they accidentally fail to deploy node_modules, or even to run 'npm install'.
// Make sure such errors are reported back to the .NET part of the app. // Make sure such errors are reported back to the .NET part of the app.
callback( callback('Prerendering failed because of an error while loading \'aspnet-prerendering\'. Error was: '
'Prerendering failed because of an error while loading \'aspnet-prerendering\'. Error was: '
+ ex.stack + ex.stack
+ '\nCurrent directory is: ' + '\nCurrent directory is: '
+ process.cwd() + process.cwd());
);
return; return;
} }
return aspNetPrerendering.renderToString.apply(this, arguments); return aspNetPrerendering.renderToString.apply(this, arguments);
}; }
exports.renderToString = renderToString;
/***/ },
/* 2 */
/***/ function(module, exports) {
module.exports = require("aspnet-prerendering");
/***/ }
/******/ ])));

View File

@@ -1,20 +1,85 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(3);
/***/ },
/* 1 */,
/* 2 */,
/* 3 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
// Pass through the invocation to the 'aspnet-webpack' package, verifying that it can be loaded // Pass through the invocation to the 'aspnet-webpack' package, verifying that it can be loaded
module.exports.createWebpackDevServer = function (callback) { function createWebpackDevServer(callback) {
var aspNetWebpack; var aspNetWebpack;
try { try {
aspNetWebpack = require('aspnet-webpack'); aspNetWebpack = __webpack_require__(4);
} catch (ex) { }
catch (ex) {
// Developers sometimes have trouble with badly-configured Node installations, where it's unable // Developers sometimes have trouble with badly-configured Node installations, where it's unable
// to find node_modules. Or they accidentally fail to deploy node_modules, or even to run 'npm install'. // to find node_modules. Or they accidentally fail to deploy node_modules, or even to run 'npm install'.
// Make sure such errors are reported back to the .NET part of the app. // Make sure such errors are reported back to the .NET part of the app.
callback( callback('Webpack dev middleware failed because of an error while loading \'aspnet-webpack\'. Error was: '
'Webpack dev middleware failed because of an error while loading \'aspnet-webpack\'. Error was: '
+ ex.stack + ex.stack
+ '\nCurrent directory is: ' + '\nCurrent directory is: '
+ process.cwd() + process.cwd());
);
return; return;
} }
return aspNetWebpack.createWebpackDevServer.apply(this, arguments); return aspNetWebpack.createWebpackDevServer.apply(this, arguments);
}; }
exports.createWebpackDevServer = createWebpackDevServer;
/***/ },
/* 4 */
/***/ function(module, exports) {
module.exports = require("aspnet-webpack");
/***/ }
/******/ ])));

View File

@@ -0,0 +1,20 @@
// Pass through the invocation to the 'aspnet-prerendering' package, verifying that it can be loaded
export function renderToString(callback) {
let aspNetPrerendering;
try {
aspNetPrerendering = require('aspnet-prerendering');
} catch (ex) {
// Developers sometimes have trouble with badly-configured Node installations, where it's unable
// to find node_modules. Or they accidentally fail to deploy node_modules, or even to run 'npm install'.
// Make sure such errors are reported back to the .NET part of the app.
callback(
'Prerendering failed because of an error while loading \'aspnet-prerendering\'. Error was: '
+ ex.stack
+ '\nCurrent directory is: '
+ process.cwd()
);
return;
}
return aspNetPrerendering.renderToString.apply(this, arguments);
}

View File

@@ -0,0 +1,20 @@
// Pass through the invocation to the 'aspnet-webpack' package, verifying that it can be loaded
export function createWebpackDevServer(callback) {
let aspNetWebpack;
try {
aspNetWebpack = require('aspnet-webpack');
} catch (ex) {
// Developers sometimes have trouble with badly-configured Node installations, where it's unable
// to find node_modules. Or they accidentally fail to deploy node_modules, or even to run 'npm install'.
// Make sure such errors are reported back to the .NET part of the app.
callback(
'Webpack dev middleware failed because of an error while loading \'aspnet-webpack\'. Error was: '
+ ex.stack
+ '\nCurrent directory is: '
+ process.cwd()
);
return;
}
return aspNetWebpack.createWebpackDevServer.apply(this, arguments);
}

View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es3",
"module": "commonjs",
"moduleResolution": "node",
"types": ["node"]
},
"exclude": [
"node_modules"
]
}

View File

@@ -0,0 +1,18 @@
{
"name": "spaservices",
"version": "1.0.0",
"description": "This is not really an NPM package and will not be published. This file exists only to reference compilation tools.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/webpack"
},
"author": "Microsoft",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^6.0.42",
"ts-loader": "^0.8.2",
"typescript": "^2.0.0",
"webpack": "^1.13.1"
}
}

View File

@@ -26,5 +26,11 @@
"embed": [ "embed": [
"Content/**/*" "Content/**/*"
] ]
},
"scripts": {
"prepublish": [
"npm install",
"node node_modules/webpack/bin/webpack.js"
]
} }
} }

View File

@@ -0,0 +1,26 @@
module.exports = {
target: 'node',
externals: [
// These NPM modules are loaded dynamically at runtime, rather than being bundled into the Content/Node/*.js files
// So, at runtime, they have to either be in node_modules or be built-in Node modules (e.g., 'fs')
'aspnet-prerendering',
'aspnet-webpack'
],
resolve: {
extensions: [ '.ts' ]
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts-loader' },
]
},
entry: {
'prerenderer': ['./TypeScript/Prerenderer'],
'webpack-dev-middleware': ['./TypeScript/WebpackDevMiddleware'],
},
output: {
libraryTarget: 'commonjs',
path: './Content/Node',
filename: '[name].js'
}
};