use rollup-plugin-cheap-ts
This commit is contained in:
parent
8ba077abee
commit
43c3a12b86
2 changed files with 4 additions and 37 deletions
|
@ -28,11 +28,12 @@
|
|||
"homepage": "https://conduitry.io/defiler",
|
||||
"devDependencies": {
|
||||
"rollup": "*",
|
||||
"rollup-plugin-cheap-ts": "Conduitry/rollup-plugin-cheap-ts#semver:*",
|
||||
"typescript": "*",
|
||||
"@types/node": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc && rollup -c",
|
||||
"build": "rollup -c",
|
||||
"dev": "rollup -cw",
|
||||
"prepare": "npm run build"
|
||||
}
|
||||
|
|
|
@ -1,43 +1,9 @@
|
|||
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) };
|
||||
}
|
||||
};
|
||||
}
|
||||
import cheapTS from 'rollup-plugin-cheap-ts';
|
||||
|
||||
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,
|
||||
},
|
||||
plugins: [cheapTS()],
|
||||
output: [
|
||||
{
|
||||
file: './dist/index.cjs.js',
|
||||
|
|
Loading…
Add table
Reference in a new issue