Я работаю над проектом ESNext TypeScript.В настоящее время у меня возникают трудности с запуском моего компоновщика (Rollup) и модульных тестов (Mocha / Chai).Я был совершенно сбит с толку, используя tsc
или babel
для процесса компиляции, и я просто не могу себе представить, как все это будет работать.
Пока что яиметь следующие конфиги:
tsconfig.json (основная конфигурация для проекта; используется в rollup.config.json)
{
"compilerOptions": {
"target": "esnext",
"module": "es2015",
"lib": ["esnext", "dom"],
"declaration": true,
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"moduleResolution": "node",
"baseUrl": "./",
"types": [
"node",
"three"
],
"esModuleInterop": true,
"inlineSourceMap": true,
"pretty": true,
"skipLibCheck": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
]
}
rollup.config.js (накопительный файл для основного модуля проекта
import typescript from 'rollup-plugin-typescript2';
import babel from 'rollup-plugin-babel';
import globals from 'rollup-plugin-node-globals';
import builtins from '@joseph184/rollup-plugin-node-builtins';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import pkg from "./package.json";
export default [
{
input: './src/index.ts',
plugins: [
typescript(),
],
external: [
"three"
],
output: [
{
file: pkg.module,
format: 'es'
}
]
},
{
input: './src/index.ts',
plugins: [
resolve({
preferBuiltins: true,
mainFields: ['module', 'main'],
}),
globals({
process: true,
global: true,
dirname: true,
filename: true
}),
builtins(),
commonjs(),
typescript(),
babel({
babelrc: true
}),
],
external: [
"three"
],
output: [ // Required; Array = multiple outputs
{
file: pkg.main,
format: 'umd',
name: 'Divine'
},
{
file: "lib/divine.cjs.js",
format: 'cjs'
}
]
}
]
.babelrc (опции babel для связывания модулей основного проекта)
{
"presets": [
["@babel/preset-env", {
"useBuiltIns": "entry",
"debug": "true"
}],
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-arrow-functions",
"@babel/plugin-syntax-dynamic-import"
],
"compact": "auto",
"exclude": [
"./src/**/test/**/*.spec.ts",
"./node_modules/*"
]
}
tsconfig.test.json (конфигурация tsc
используется для mocha
с ts-node
как компилятор)
{
"compililerOptions": {
"target": "esnext",
"module": "commonjs",
"lib": ["esnext", "dom"],
"moduleResolution": "node",
"esModuleInterop": true,
"types": [
"chai",
"mocha",
],
"exclude": [
"src/core/loggingsystem/test",
"src/core/messagesystem/test"
]
}
}
Мой главный вопрос: что мне использовать для esnext to es5 (для большинства браузеров)?Я хочу работать в коде ESNext, но я хочу, чтобы мои этапы сборки были наименьшими из возможных.Лучше использовать tsc
изначально, или я должен смешать / полностью использовать Babel?У меня были очень трудные времена с моими сборками, так как я все еще совершенно не уверен в том, как все должно сочетаться.
Любая помощь очень ценится!