tidy build process
This commit is contained in:
parent
c7c7d8ce1b
commit
e1b60c0bb5
5 changed files with 52 additions and 49 deletions
|
@ -32,8 +32,8 @@
|
|||
"@types/node": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc && rollup -c rollup/prod.js",
|
||||
"dev": "rollup -c rollup/dev.js -w",
|
||||
"build": "tsc && rollup -c",
|
||||
"dev": "rollup -cw",
|
||||
"prepare": "npm run build"
|
||||
}
|
||||
}
|
||||
|
|
50
rollup.config.js
Normal file
50
rollup.config.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
let transform;
|
||||
|
||||
if (process.env.ROLLUP_WATCH === 'true') {
|
||||
const { transpileModule } = require('typescript');
|
||||
const tsconfig = require('./tsconfig.json');
|
||||
transform = (code, id) => {
|
||||
if (id.endsWith('.ts')) {
|
||||
const { outputText, sourceMapText } = transpileModule(code, tsconfig);
|
||||
return { code: outputText, map: JSON.parse(sourceMapText) };
|
||||
}
|
||||
};
|
||||
} else {
|
||||
const { readFile, unlink } = require('fs');
|
||||
const { promisify } = require('util');
|
||||
transform = async (code, id) => {
|
||||
if (id.endsWith('.ts')) {
|
||||
id = id.slice(0, -2) + 'js';
|
||||
const [js, map] = await Promise.all(
|
||||
[id, id + '.map'].map(async path => {
|
||||
const data = await promisify(readFile)(path);
|
||||
unlink(path, () => null);
|
||||
return data.toString();
|
||||
}),
|
||||
);
|
||||
return { code: js, map: JSON.parse(map) };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
input: './src/index',
|
||||
external: name => /^[a-z]/.test(name),
|
||||
plugins: {
|
||||
resolveId(importee, importer) {
|
||||
if (/\/[^.]+$/.test(importee)) {
|
||||
return this.resolveId(importee + '.ts', importer);
|
||||
}
|
||||
},
|
||||
transform,
|
||||
},
|
||||
output: [
|
||||
{
|
||||
file: './dist/index.cjs.js',
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
interop: false,
|
||||
},
|
||||
{ file: './dist/index.es.js', format: 'es', sourcemap: true },
|
||||
],
|
||||
};
|
|
@ -1,20 +0,0 @@
|
|||
export default {
|
||||
input: './src/index',
|
||||
external: name => /^[a-z]/.test(name),
|
||||
plugins: {
|
||||
resolveId(importee, importer) {
|
||||
if (/\/[^.]+$/.test(importee)) {
|
||||
return this.resolveId(importee + '.ts', importer);
|
||||
}
|
||||
},
|
||||
},
|
||||
output: [
|
||||
{
|
||||
file: './dist/index.cjs.js',
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
interop: false,
|
||||
},
|
||||
{ file: './dist/index.es.js', format: 'es', sourcemap: true },
|
||||
],
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
import common from './common.js';
|
||||
import { transpileModule } from 'typescript';
|
||||
const tsconfig = require('../tsconfig.json');
|
||||
common.plugins.transform = (code, id) => {
|
||||
if (id.endsWith('.ts')) {
|
||||
const { outputText, sourceMapText } = transpileModule(code, tsconfig);
|
||||
return { code: outputText, map: JSON.parse(sourceMapText) };
|
||||
}
|
||||
};
|
||||
export default common;
|
|
@ -1,17 +0,0 @@
|
|||
import common from './common.js';
|
||||
import { readFile, unlink } from 'fs';
|
||||
import { promisify } from 'util';
|
||||
common.plugins.transform = async (code, id) => {
|
||||
if (id.endsWith('.ts')) {
|
||||
id = id.slice(0, -2) + 'js';
|
||||
const [js, map] = await Promise.all(
|
||||
[id, id + '.map'].map(async path => {
|
||||
const data = await promisify(readFile)(path);
|
||||
unlink(path, () => null);
|
||||
return data.toString();
|
||||
}),
|
||||
);
|
||||
return { code: js, map: JSON.parse(map) };
|
||||
}
|
||||
};
|
||||
export default common;
|
Loading…
Add table
Reference in a new issue