Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bundled typescript #138

Merged
merged 1 commit into from Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -86,7 +86,7 @@
"the-answer": "^1.0.0",
"ts-loader": "^5.3.1",
"twilio": "^3.23.2",
"typescript": "^3.2.1",
"typescript": "^3.2.2",
"vue": "^2.5.17",
"vue-server-renderer": "^2.5.17",
"webpack": "^4.26.0",
Expand Down
6 changes: 6 additions & 0 deletions scripts/build.js
Expand Up @@ -66,6 +66,12 @@ async function main() {
writeFileSync(__dirname + "/../dist/ncc/loaders/shebang-loader.js", shebangLoader);
writeFileSync(__dirname + "/../dist/ncc/loaders/ts-loader.js", tsLoader);

// copy typescript types
await copy(
__dirname + "/../node_modules/typescript/lib/*.ts",
__dirname + "/../dist/ncc/loaders/lib/"
);

// copy webpack buildin
await copy(
__dirname + "/../node_modules/webpack/buildin/*.js",
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Expand Up @@ -105,7 +105,7 @@ module.exports = async (
},
{
test: /\.tsx?$/,
use: [{ loader: __dirname + "/loaders/ts-loader.js" }]
use: [{ loader: __dirname + "/loaders/ts-loader.js", options: {} }]
}
]
},
Expand All @@ -128,10 +128,14 @@ module.exports = async (
/webpackEmptyAsyncContext|webpackEmptyContext/
)
) {
module.type = 'HACK'; // hack to ensure __webpack_require__ is added to wrapper
return moduleSourcePostModule._value.replace(
"var e = new Error",
`try { return require(req) }\ncatch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e }` +
`\nvar e = new Error`
`if (typeof req === 'number' && __webpack_require__.m[req])\n` +
` return __webpack_require__(req);\n` +
`try { return require(req) }\n` +
`catch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e }\n` +
`var e = new Error`
);
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/loaders/ts-loader.js
Expand Up @@ -2,4 +2,12 @@
// optional bundle for the ts-loader, that
// doesn't get loaded unless the user is
// compiling typescript
module.exports = require("ts-loader");
const { getOptions } = require("loader-utils");
const loader = require("ts-loader");
const tsId = require.resolve("typescript");
module.exports = function () {
const options = getOptions(this);
if (!options.compiler)
options.compiler = tsId;
return loader.apply(this, arguments);
};