Here is an example of our gulp script that handles transpiling TypeScript:
const gulp = require('gulp');
const typescript = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const tscConfig = require('./tsconfig.json');
const inlineNg2Templates = require('gulp-inline-ng2-template');
const paths = {
distAssetsFolder: 'dist/assets',
distFolder: 'dist',
distLibFolder: 'dist/lib',
distFiles: 'dist/**/*',
srcMapFolder: './maps',
srcFiles: 'src/**/*',
srcAssetFolder: 'src/assets/**/*',
srcMainSassFile: 'src/**/main.scss',
srcTsFiles: 'src/**/*.ts',
srcTestFiles : 'src/**/*.spec.ts'
};
gulp.task('transpile-typescript', ['clean:dist'], function () {
return gulp
.src(paths.srcTsFiles)
.pipe(inlineNg2Templates({ useRelativePaths: true}))
.pipe(sourcemaps.init())
.pipe(typescript(tscConfig.compilerOptions))
.pipe(sourcemaps.write(paths.srcMapFolder))
.pipe(gulp.dest(paths.distFolder));
});
We utilize JSPM for managing dependencies with a jspm-config.js file at the project's root.
When we run any task in our gulp script, we encounter errors such as:
src\app\sidebar\panel.component.ts(1,46): error TS2307: Cannot find module 'angular2/core'. src\app\sidebar\panel.component.ts(2,30): error TS2307: Cannot find module 'angular2/http'. src\app\uiComponents\demo\demo.ts(1,25): error TS2307: Cannot find module 'angular2/core'. src\app\uiComponents\modal\modal.ts(1,54): error TS2307: Cannot find module 'angular2/core'. src\app\uiComponents\modal\modal.ts(2,23): error TS2307: Cannot find module 'angular2/common'.
Interestingly, despite these errors, the application functions properly. The errors are dynamically resolved at runtime by referencing the mappings in our jspm-config.js file, which resembles this structure:
"angular2": "npm:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80e1eee7f5ece1f2b2c0b2aeb0aeb0ade2e5f4e1aeb7">[email protected]</a>",
It seems that we need to incorporate the jspm config during transpile time, and we're seeking guidance on how to achieve that.
Any suggestions or solutions would be greatly appreciated!