Skip to content

Commit

Permalink
TINY-3074: Switched to ts-loader which allows overriding tsc compiler…
Browse files Browse the repository at this point in the history
… options
  • Loading branch information
TheSpyder committed Mar 20, 2019
1 parent 9f73af1 commit d697a07
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 136 deletions.
6 changes: 4 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@ephox/bedrock",
"version": "4.0.14",
"version": "4.1.0",
"description": "NodeJS test runner",
"repository": {
"type": "git",
Expand All @@ -22,11 +22,11 @@
"private": false,
"dependencies": {
"async": "^1.5.2",
"awesome-typescript-loader": "^5.2.1",
"babel-polyfill": "^6.23.0",
"command-line-args": "^3.0.0",
"command-line-usage": "^3.0.1",
"finalhandler": "^0.4.1",
"fork-ts-checker-webpack-plugin": "^1.0.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jquery": "^3.0.0",
"mkdirp": "^0.5.1",
Expand All @@ -36,6 +36,8 @@
"selenium-webdriver": "^3",
"serve-static": "^1.10.2",
"source-map-loader": "^0.2.3",
"ts-loader": "^5.3.3",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"typescript": "^3.1.6",
"webpack": "^4.25.1",
"webpack-dev-server": "^3.2.1",
Expand Down
45 changes: 25 additions & 20 deletions src/js/bedrock/compiler/webpack.js
@@ -1,4 +1,5 @@
var { CheckerPlugin, TsConfigPathsPlugin } = require('awesome-typescript-loader');
const TsConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
var path = require('path');
var fs = require('fs');
var mkdirp = require('mkdirp');
Expand All @@ -8,21 +9,18 @@ var webpack = require("webpack");
const WebpackDevServer = require('webpack-dev-server');
const imports = require('./imports');

let getWebPackConfig = function (tsConfigFile, scratchDir, scratchFile, dest, coverage) {
let getWebPackConfig = function (tsConfigFile, scratchFile, dest, coverage, manualMode) {
return {
context: path.resolve(__dirname),
stats: 'none',
entry: scratchFile,
devtool: 'eval-cheap-module-source-map',
mode: 'development',
devtool: manualMode ? 'source-map' : false,
mode: manualMode ? 'development' : 'none',

resolve: {
extensions: ['.ts', '.js'],
plugins: [
new TsConfigPathsPlugin({
options: {
configFileName: tsConfigFile
}
configFile: tsConfigFile
})
]
},
Expand All @@ -39,13 +37,17 @@ let getWebPackConfig = function (tsConfigFile, scratchDir, scratchFile, dest, co
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
loader: 'ts-loader',
options: {
configFileName: tsConfigFile,
compiler: 'typescript',
useCache: false,
transpileOnly: false,
cacheDirectory: path.join(scratchDir, 'awcache')
colors: false,
configFile: tsConfigFile,
transpileOnly: true,
experimentalWatchApi: true,
projectReferences: true,
compilerOptions: {
rootDir: '.',
declarationMap: false
}
}
}
]
Expand All @@ -71,7 +73,11 @@ let getWebPackConfig = function (tsConfigFile, scratchDir, scratchFile, dest, co
},

plugins: [
new CheckerPlugin({})
new ForkTsCheckerWebpackPlugin({
tsconfig: tsConfigFile,
colors: manualMode,
async: manualMode
})
],

output: {
Expand All @@ -88,14 +94,14 @@ let compile = function (tsConfigFile, scratchDir, exitOnCompileError, srcFiles,
mkdirp.sync(path.dirname(scratchFile));
fs.writeFileSync(scratchFile, imports.generateImports(true, scratchFile, srcFiles));

webpack(getWebPackConfig(tsConfigFile, scratchDir, scratchFile, dest, coverage), (err, stats) => {
webpack(getWebPackConfig(tsConfigFile, scratchFile, dest, coverage, false), (err, stats) => {
if (err || stats.hasErrors()) {
let msg = stats.toString({
all: false,
errors: true,
moduleTrace: true,
chunks: false,
colors: true
colors: false
});

console.log(msg);
Expand All @@ -121,12 +127,11 @@ let devserver = function (settings, done) {
mkdirp.sync(path.dirname(scratchFile));
fs.writeFileSync(scratchFile, imports.generateImports(true, scratchFile, settings.testfiles));

const compiler = webpack(getWebPackConfig(tsConfigFile, scratchDir, scratchFile, dest, settings.coverage));
const compiler = webpack(getWebPackConfig(tsConfigFile, scratchFile, dest, settings.coverage, true));

// Prevents webpack from doing a recompilation of a change of tests.ts over and over
compiler.plugin('emit', function(compilation, callback) {
compiler.hooks.emit.tap('bedrock', function (compilation) {
compilation.fileDependencies.delete(scratchFile);
callback();
});

return new WebpackDevServer(compiler, {
Expand Down

0 comments on commit d697a07

Please sign in to comment.