Skip to content

Instantly share code, notes, and snippets.

@ahomu
Last active October 14, 2019 14:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahomu/1973a81d175400aaa2ba to your computer and use it in GitHub Desktop.
Save ahomu/1973a81d175400aaa2ba to your computer and use it in GitHub Desktop.
browserify(&watchify) で tsify --target=es6 と babelify を併用する
{
"modules": "commonStrict",
"sourceMaps": "inline",
"loose": true,
"blacklist": [
]
}
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));
}
{
"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