Typescript – tsc didn’t copy .html .css .txt to destination folder

tsc would translate .ts file to js and keep folder struction.
however, for some special file for tsc, such as .txt, .html, .css, tsc command chooses to ignore them.

we have to copy manually

for cross-platform, we are using node.js copyfiles package to do it.

but ‘copyfiles ./src/**/*.txt ./dist’ won’t work, the final result of that command is all text file would go under ‘./dist/src/path/to/file.txt’

but luckily copyfiles has options to handle and it is key reason why we uses it beside cross-platform.

in package.json add

1
2
3
4
5
  "scripts": {
    ...
    "copy-template": "copyfiles -u 1 ./src/**/*.txt ./dist"
    ...
  }

another way to is to use gulpfiles.js and gulp command line.

1
2
3
4
gulp.task('copy-template', function() {
     return gulp.src('./src/**/*.txt', {base: './src'})
            .pipe(gulp.dest('./dist'));
});

later on, add package.json to invoke this gulpfiles.js

This entry was posted in Typescript. Bookmark the permalink.