diff --git a/packages/addon-dev/sample-typescript-babel.config.cjs b/packages/addon-dev/sample-typescript-babel.config.cjs new file mode 100644 index 000000000..2e0dbc367 --- /dev/null +++ b/packages/addon-dev/sample-typescript-babel.config.cjs @@ -0,0 +1,27 @@ +'use strict'; + +const { resolve } = require; + +module.exports = { + presets: [resolve('@babel/preset-typescript')], + plugins: [ + [ + resolve('@babel/plugin-transform-typescript'), + { + allowDeclareFields: true, + onlyRemoveTypeImports: true, + // Default enums are IIFEs + optimizeConstEnums: true, + }, + ], + [ + resolve('@babel/plugin-proposal-decorators'), + { + // The stage 1 implementation + legacy: true, + }, + ], + [resolve('@babel/plugin-proposal-class-properties')], + resolve('@embroider/addon-dev/template-colocation-plugin'), + ], +}; diff --git a/packages/addon-dev/sample-typescript-rollup.config.mjs b/packages/addon-dev/sample-typescript-rollup.config.mjs new file mode 100644 index 000000000..886e87211 --- /dev/null +++ b/packages/addon-dev/sample-typescript-rollup.config.mjs @@ -0,0 +1,91 @@ +import ts from 'rollup-plugin-ts'; +import { defineConfig } from 'rollup'; + +import { Addon } from '@embroider/addon-dev/rollup'; + +const addon = new Addon({ + srcDir: 'src', + destDir: 'dist', +}); + +export default defineConfig({ + // https://github.com/rollup/rollup/issues/1828 + watch: { + chokidar: { + usePolling: true, + }, + }, + output: { + ...addon.output(), + sourcemap: true, + // Until a bug with the ember-cli-htmlbars-removal transform is fixed, you + // may need + // hoistTransitiveImports: false + // specified here as well + }, + plugins: [ + // These are the modules that users should be able to import from your + // addon. Anything not listed here may get optimized away. + addon.publicEntrypoints([ + 'index.ts', + 'components/**/*.ts', + 'helpers/**/*.ts', + 'modifiers/**/*.ts', + 'services/**/*.ts', + 'test-support/**/*.ts', + ]), + + // These are the modules that should get reexported into the traditional + // "app" tree. Things in here should also be in publicEntrypoints above, but + // not everything in publicEntrypoints necessarily needs to go here. + addon.appReexports([ + 'index.js', + 'components/**/*.js', + 'helpers/**/*.js', + 'modifiers/**/*.js', + 'services/**/*.js', + 'test-support/**/*.js', + ]), + // This babel config should *not* apply presets or compile away ES modules. + // It exists only to provide development niceties for you, like automatic + // template colocation. + // See `babel.config.json` for the actual Babel configuration! + ts({ + // can be changed to swc or other transpilers later + // but we need the ember plugins converted first + // (template compilation and co-location) + transpiler: 'babel', + // without the browserlist, recently landed JS features are polyfilled. + // It should be primarily up to the consuming app whether or not they need to + // polyfill whatever JS features. + browserslist: ['last 2 firefox versions', 'last 2 chrome versions'], + tsconfig: { + // when `hooks` is specified, fileName is required + fileName: 'tsconfig.json', + hook: (config) => ({ + ...config, + declaration: true, + declarationMap: true, + // See: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#beta-delta + // Allows us to use `exports` to define types per export + // However, we can't use that feature until the minimum supported TS is 4.7+ + declarationDir: './dist', + }), + }, + }), + + // Follow the V2 Addon rules about dependencies. Your code can import from + // `dependencies` and `peerDependencies` as well as standard Ember-provided + // package names. + addon.dependencies(), + + // Ensure that standalone .hbs files are properly integrated as Javascript. + addon.hbs(), + + // addons are allowed to contain imports of .css files, which we want rollup + // to leave alone and keep in the published output. + addon.keepAssets(['**/*.css']), + + addon.clean(), + ], +});