Last active
October 14, 2019 14:50
-
-
Save ahomu/1973a81d175400aaa2ba to your computer and use it in GitHub Desktop.
browserify(&watchify) で tsify --target=es6 と babelify を併用する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"modules": "commonStrict", | |
"sourceMaps": "inline", | |
"loose": true, | |
"blacklist": [ | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const browserify = require('browserify'); | |
const licensify = require('licensify'); | |
const tsify = require('tsify'); | |
const babelify = require('babelify'); | |
const watchify = require('watchify'); | |
const EXTENSIONS = ['.js', '.ts', '.json']; | |
const BUNDLE_INDEX = './src/index.ts'; | |
const BUNDLE_OUTPUT = './xxxxxxxxxxx.js'; | |
function applyBundleConf(b) { | |
return b | |
.plugin(licensify) | |
.plugin(tsify) | |
.transform(babelify.configure({ | |
extensions : EXTENSIONS | |
})) | |
.add(BUNDLE_INDEX); | |
} | |
if (process.argv[2] === '--watch') { | |
const b = applyBundleConf(browserify({ | |
extensions : EXTENSIONS, | |
debug : true, | |
cache : {}, | |
packageCache : {}, | |
plugin : [watchify] | |
})).on('update', handler); | |
function handler() { | |
console.log('update'); | |
b.bundle().pipe(fs.createWriteStream(BUNDLE_OUTPUT)); | |
} | |
handler(); | |
} else { | |
applyBundleConf(browserify({ | |
extensions : EXTENSIONS, | |
debug : true | |
})).bundle().pipe(fs.createWriteStream(BUNDLE_OUTPUT)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"moduleResolution": "node", | |
"noImplicitAny": true, | |
"inlineSourceMap": true, | |
"jsx": "react", | |
"outDir": "./dist", | |
"rootDir": "./src", | |
"target": "es6" | |
}, | |
"exclude": [ | |
"node_modules" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment