-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a sample rollup config for typescript #1095
Comments
ah for babel I needed to use I forgot about that. import { createRequire } from 'module';
import { precompile } from '@glimmer/compiler';
const require = createRequire(import.meta.url);
const { resolve } = require;
export default {
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'),
{
// Only support browsers that also support class properties...
// If all addons do this, it greatly reduces shipped JS
loose: true,
},
],
[
resolve('babel-plugin-ember-template-compilation'),
{
precompile,
enableLegacyModules: ['ember-cli-htmlbars'],
},
],
resolve('@embroider/addon-dev/template-colocation-plugin'),
],
}; So now all that's left are all the other issues. lol |
Totally support this idea. I haven't tried to have an addon v2 with hbs and TS files, but I did with glimmer-apollo which is TS files only. I suggest using |
Yeah, my issues with that plugin are no more, as my issue was actually the missing babel plugin. Just need better |
@NullVoxPopuli Can you post the working example using |
// @ts-nocheck
import path from 'path';
import alias from '@rollup/plugin-alias';
import ts from 'rollup-plugin-ts';
import { babel } from '@rollup/plugin-babel';
import { defineConfig } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { Addon } from '@embroider/addon-dev/rollup';
import babelConfig from './babel.config';
const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});
const extensions = ['.js', '.ts'];
const transpilation = [
// Instruct rollup how to follow import paths for typescript files
// (in JS-only libraries, this isn't needed)
nodeResolve({ resolveOnly: ['./'], extensions: [...extensions, '.hbs'] }),
// Allow top-level imports (what folks are used to from v1 addons)
// During the build, anything referencing a top-level import will be
// replaced with a relative import.
// DANGER: it's somewhat easy to cause circular references with this tool
alias({
entries: [
{
find: '#types',
replacement: path.resolve('src', '-private', 'types.ts'),
},
{
find: <my-addon>',
replacement: path.resolve('src'),
},
{
find: '<my-addon>/(.*)',
replacement: path.resolve('src/$1'),
},
],
}),
// 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!
// babel({ babelHelpers: 'bundled', extensions }),
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',
browserslist: false,
babelConfig,
tsconfig: {
fileName: 'tsconfig.json',
hook: (config) => ({ ...config, declaration: true }),
},
}),
// 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']),
];
const globallyAvailable = ['src/components/**/*.{js,ts}', 'src/services/*.{js,ts}'];
export default [
defineConfig({
input: 'src/index.ts',
output: { ...addon.output(), entryFileNames: 'index.js' },
plugins: [
...transpilation,
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints([...globallyAvailable]),
// 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(globallyAvailable),
],
}),
defineConfig({
input: 'src/test-support/index.ts',
output: { ...addon.output(), entryFileNames: 'test-support.js' },
plugins: [
...transpilation,
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints(['test-support/index.js']),
],
}),
]; |
Ok, so the above doesn't work with components/services. I'm going to update the original post for easier discoverability with the working config that I have (it's an oofta) |
Closing, as I think we have a solid option for TS now -- gonna throw a PR up |
Updated
I think I got everything working output wise.
I still have the issue where the consuming app is looking for dist/addon, but I can debug that.
Here is my current config which appears to generate things in a way
@embroider/addon-dev
is expecting:dist/_app_
Notes
./config/babel.config.js
./config/rollup.config.js
"build:js": "rollup -c ./config/rollup.config.js",
tsc
by itself (somehow)Original question / set of problems
Related to: #1094
I have this so far, but certain things don't work:
dist/addon
Babel config
relevant package.json entries
And the command I'm running:
And a sample of the output
dist/index.js
:I did try rollup-plugin-ts, however, it has similar problems:
babelConfig
), hbs files are not properly converted to javascriptThe text was updated successfully, but these errors were encountered: