Skip to content

Commit

Permalink
Add option to compile bundled files and .d.ts files only
Browse files Browse the repository at this point in the history
  • Loading branch information
maier49 committed Oct 25, 2017
1 parent cc1c037 commit 4ad8846
Show file tree
Hide file tree
Showing 77 changed files with 2,685 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Expand Up @@ -110,7 +110,7 @@ function getLoaderOptions(loader: Webpack) {
}

type ValidLoaderOptions = keyof LoaderOptions;
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'happyPackMode', 'getCustomTransformers'];
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs', 'onlyCompileBundledFiles' /* DEPRECATED */, 'happyPackMode', 'getCustomTransformers'];

/**
* Validate the supplied loader options.
Expand Down Expand Up @@ -146,7 +146,8 @@ function makeLoaderOptions(instanceName: string, configFileOptions: Partial<Load
transformers: {},
entryFileCannotBeJs: false,
happyPackMode: false,
colors: true
colors: true,
onlyCompileBundledFiles: false
} as Partial<LoaderOptions>, configFileOptions, loaderOptions);

options.ignoreDiagnostics = arrify(options.ignoreDiagnostics).map(Number);
Expand Down
4 changes: 2 additions & 2 deletions src/instances.ts
Expand Up @@ -5,7 +5,7 @@ import chalk, { Chalk } from 'chalk';

import { makeAfterCompile } from './after-compile';
import { getConfigFile, getConfigParseResult } from './config';
import { EOL } from './constants';
import { EOL, dtsDtsxRegex } from './constants';
import { getCompilerOptions, getCompiler } from './compilerSetup';
import { hasOwnProperty, makeError, formatErrors, registerWebpackErrors } from './utils';
import * as logger from './logger';
Expand Down Expand Up @@ -118,7 +118,7 @@ function successfulTypeScriptInstance(
// Load initial files (core lib files, any files specified in tsconfig.json)
let normalizedFilePath: string;
try {
const filesToLoad = configParseResult.fileNames;
const filesToLoad = loaderOptions.onlyCompileBundledFiles ? configParseResult.fileNames.filter(fileName => dtsDtsxRegex.test(fileName)) : configParseResult.fileNames;
filesToLoad.forEach(filePath => {
normalizedFilePath = path.normalize(filePath);
files[normalizedFilePath] = {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Expand Up @@ -269,6 +269,7 @@ export interface LoaderOptions {
transpileOnly: boolean;
ignoreDiagnostics: number[];
errorFormatter: (message: ErrorInfo, colors: Chalk) => string;
onlyCompileBundledFiles: boolean;
colors: boolean;
compilerOptions: typescript.CompilerOptions;
appendTsSuffixTo: RegExp[];
Expand Down
3 changes: 3 additions & 0 deletions test/comparison-tests/onlyCompileBundledFiles/app.ts
@@ -0,0 +1,3 @@
import submodule = require('./submodule/submodule');
import externalLib = require('externalLib');
externalLib.doSomething(submodule);
@@ -0,0 +1,71 @@
/******/ (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__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.85 kB 0 [emitted] main
chunk {0} bundle.js (main) 318 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 128 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0} [built]
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0} [built]
@@ -0,0 +1,71 @@
/******/ (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__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething2(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.86 kB 0 [emitted] main
chunk {0} bundle.js (main) 319 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 129 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0}
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0}
@@ -0,0 +1,9 @@
Asset Size Chunks Chunk Names
bundle.js 1.86 kB 0 [emitted] main
chunk {0} bundle.js (main) 319 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 129 bytes {0} [built] [1 error]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0}
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0}

ERROR in ./.test/onlyCompileBundledFiles/app.ts
(3,13): error TS2339: Property 'doSomething2' does not exist on type 'typeof externalLib'.
@@ -0,0 +1,71 @@
/******/ (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__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.85 kB 0 [emitted] main
chunk {0} bundle.js (main) 318 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 128 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0}
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0}
@@ -0,0 +1,71 @@
/******/ (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__) {

var submodule = __webpack_require__(1);
var externalLib = __webpack_require__(2);
externalLib.doSomething(submodule);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

var externalLib = __webpack_require__(2);
externalLib.doSomething("");
var message = "Hello from submodule";
module.exports = message;


/***/ },
/* 2 */
/***/ function(module, exports) {

module.exports = {
doSomething: function() { }
}

/***/ }
/******/ ]);
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.85 kB 0 [emitted] main
chunk {0} bundle.js (main) 318 bytes [rendered]
[0] ./.test/onlyCompileBundledFiles/app.ts 128 bytes {0} [built]
[1] ./.test/onlyCompileBundledFiles/submodule/submodule.ts 135 bytes {0} [built]
[2] ./.test/onlyCompileBundledFiles/lib/externalLib.js 55 bytes {0} [built]

0 comments on commit 4ad8846

Please sign in to comment.