Skip to content

Commit

Permalink
Updates, based on: embroider-build#1106
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jun 4, 2022
1 parent 77e739a commit b9ac048
Showing 1 changed file with 61 additions and 71 deletions.
132 changes: 61 additions & 71 deletions packages/addon-dev/sample-typescript-rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,94 +10,28 @@
import path from 'path';

import alias from '@rollup/plugin-alias';
import multiInput from 'rollup-plugin-multi-input';
import ts from 'rollup-plugin-ts';
import { defineConfig } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { Addon } from '@embroider/addon-dev/rollup';

import babelConfig from './babel.config';
import packageJson from '../package.json';
import packageJson from './package.json';

const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});

const transpilation = [
// Instruct rollup how to resolve ts and hbs imports
// (importing a template-only component, for example)
nodeResolve({ resolveOnly: ['./'], extensions: ['.js', '.ts', '.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: packageJson.name,
replacement: path.resolve('src'),
},
{
find: `${packageJson.name}/(.*)`,
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!
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,
// setting this true greatly improves performance, but
// at the cost of safety (and no declarations output in your dist directory).
transpileOnly: false,
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 = [
'components/**/*.{js,ts}', 'services/**/*.{js,ts}', 'helpers/**/*.{js,ts}',
'instance-initializers/**/*.{js,ts}'
];

// these should be JS, even though the authored format is TS
const globallyAvailable = ['components/**/*.js', 'services/*.js'];

export default defineConfig({
input: ['src/**/*{js,hbs,ts}'],
output: addon.output(),
plugins: [
// allows specifying glob inputs so we can transpile each module separately
multiInput(),

...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]),
addon.publicEntrypoints(['*.{js,ts}', ...globallyAvailable]),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
Expand All @@ -107,6 +41,62 @@ export default defineConfig({
// and updates an 'ember-addon.app-js' entry in your package.json
addon.appReexports([...globallyAvailable]),

// 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: packageJson.name,
replacement: path.resolve('src'),
},
{
find: `${packageJson.name}/(.*)`,
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!
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,
// NOTE: babel config must be CJS if in the same directory as CWD
// https://github.com/wessberg/rollup-plugin-ts/issues/167
// otherwise ESM babel.config.js can be imported and set here
// babelConfig,
// setting this true greatly improves performance, but
// at the cost of safety (and no declarations output in your dist directory).
transpileOnly: false,
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']),

// Remove leftover build artifacts when starting a new build.
addon.clean(),
],
Expand Down

0 comments on commit b9ac048

Please sign in to comment.