Skip to content

Commit

Permalink
Merge pull request #1 from josemarluedke/feat/addon-dev
Browse files Browse the repository at this point in the history
Refactor rollup config to use Embroider addon dev
  • Loading branch information
NullVoxPopuli committed Feb 3, 2022
2 parents 6697da7 + b03ce7d commit 125700f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 172 deletions.
99 changes: 25 additions & 74 deletions my-addon/config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,33 @@
// @ts-nocheck
import path from 'path';

import alias from '@rollup/plugin-alias';
import multiInput from 'rollup-plugin-multi-input';
import babel from '@rollup/plugin-babel';
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 packageJson from '../package.json';

const addon = new Addon();

const extensions = ['.js', '.ts', '.hbs'];

const USE_TS_PLUGIN = process.env.TS;
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 }),

// 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!
...[
!USE_TS_PLUGIN
?
// when using decorators, a common chunk is created "rollupPluginBabelHelpers"
// for the decorating wrapping functions
//
babel({ babelHelpers: 'bundled', extensions })
:
// this plugin forces you to rely on 'tslib'
//
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: ['last 2 firefox versions', 'last 2 chrome versions'],
// setting this true greatly improves performance, but
// at the cost of safety.
transpileOnly: false,
tsconfig: {
fileName: 'tsconfig.json',
hook: (config) => ({ ...config, declaration: true }),
},
}),
],

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: ['last 2 firefox versions', 'last 2 chrome versions'],
// setting this true greatly improves performance, but
// at the cost of safety.
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
Expand All @@ -91,23 +45,20 @@ const transpilation = [
// these should be JS, even though the authored format is TS
// Unfortunately, your local project layout has to kind of match what classic ember expects
// so that all the app-re-exports can be properly generated
const globallyAvailable = ['components/**/*.js', 'instance-initializers/*.js', 'helpers/**/*.js'];
const globallyAvailable = [
'components/**/*.{ts,js}',
'instance-initializers/*.{ts,js}',
'helpers/**/*.{ts,js}',
];

export default defineConfig({
external: ['tslib'],
input: ['src/**/*{js,hbs,ts}'],
output: {
sourcemap: true,
format: 'es',
dir: 'dist',
},
output: addon.output(),
plugins: [
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 Down
16 changes: 8 additions & 8 deletions my-addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
"@embroider/addon-dev": "1.0.0",
"@glimmer/compiler": "^0.83.1",
"@nullvoxpopuli/eslint-configs": "^2.1.10",
"@rollup/plugin-alias": "3.1.9",
"@rollup/plugin-babel": "5.3.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@types/ember__application": "^3.16.3",
"@types/ember__component": "^3.16.6",
"@types/ember__debug": "^3.16.5",
Expand All @@ -73,7 +70,6 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"rollup": "2.67.0",
"rollup-plugin-multi-input": "1.3.1",
"rollup-plugin-ts": "2.0.5",
"semantic-release": "^19.0.0",
"typescript": "^4.4.2"
Expand All @@ -87,16 +83,20 @@
"ember": {
"edition": "octane"
},
"peerDependencies": {
"ember-source": "*",
"@glimmer/component": "*",
"@glimmer/tracking": "*"
},
"ember-addon": {
"version": 2,
"type": "addon",
"main": "./config/addon-main.cjs",
"app-js": {
"./helpers/stringify.js": "./dist/_app_/helpers/stringify.js",
"./helpers/stringify2.js": "./dist/_app_/helpers/stringify2.js",
"./components/demo/index.js": "./dist/_app_/components/demo/index.js",
"./components/flat-demo.js": "./dist/_app_/components/flat-demo.js",
"./instance-initializers/example-instance-initializer.js": "./dist/_app_/instance-initializers/example-instance-initializer.js",
"./components/demo/index.js": "./dist/_app_/components/demo/index.js"
"./helpers/stringify.js": "./dist/_app_/helpers/stringify.js",
"./instance-initializers/example-instance-initializer.js": "./dist/_app_/instance-initializers/example-instance-initializer.js"
}
},
"volta": {
Expand Down
7 changes: 3 additions & 4 deletions testing/ember-app/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{page-title "EmberApp"}}
{{page-title 'EmberApp'}}

{{!-- The following component displays Ember's default welcome message. --}}
<WelcomePage />
{{!-- Feel free to remove this! --}}
<FlatDemo />
<Demo />

{{outlet}}
90 changes: 4 additions & 86 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
dependencies:
"@babel/types" "^7.16.7"

"@babel/helper-module-imports@^7.10.4", "@babel/helper-module-imports@^7.12.13", "@babel/helper-module-imports@^7.16.0", "@babel/helper-module-imports@^7.16.7":
"@babel/helper-module-imports@^7.12.13", "@babel/helper-module-imports@^7.16.0", "@babel/helper-module-imports@^7.16.7":
version "7.16.7"
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.16.7.tgz#25612a8091a999704461c8a222d0efec5d091437"
integrity sha512-LVtS6TqjJHFc+nYeITRo6VLXve70xmq7wPhWTqDJusJEgGmkAACWwMiTNrvfoQo6hEhFwAIixNkvB0jPXDL8Wg==
Expand Down Expand Up @@ -1972,42 +1972,6 @@
dependencies:
"@octokit/openapi-types" "^11.2.0"

"@rollup/plugin-alias@3.1.9":
version "3.1.9"
resolved "https://registry.npmjs.org/@rollup/plugin-alias/-/plugin-alias-3.1.9.tgz#a5d267548fe48441f34be8323fb64d1d4a1b3fdf"
integrity sha512-QI5fsEvm9bDzt32k39wpOwZhVzRcL5ydcffUHMyLVaVaLeC70I8TJZ17F1z1eMoLu4E/UOcH9BWVkKpIKdrfiw==
dependencies:
slash "^3.0.0"

"@rollup/plugin-babel@5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-5.3.0.tgz#9cb1c5146ddd6a4968ad96f209c50c62f92f9879"
integrity sha512-9uIC8HZOnVLrLHxayq/PTzw+uS25E14KPUBh5ktF+18Mjo5yK0ToMMx6epY0uEgkjwJw0aBW4x2horYXh8juWw==
dependencies:
"@babel/helper-module-imports" "^7.10.4"
"@rollup/pluginutils" "^3.1.0"

"@rollup/plugin-node-resolve@^13.0.6":
version "13.1.3"
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.1.3.tgz#2ed277fb3ad98745424c1d2ba152484508a92d79"
integrity sha512-BdxNk+LtmElRo5d06MGY4zoepyrXX1tkzX2hrnPEZ53k78GuOMWLqmJDGIIOPwVRIFZrLQOo+Yr6KtCuLIA0AQ==
dependencies:
"@rollup/pluginutils" "^3.1.0"
"@types/resolve" "1.17.1"
builtin-modules "^3.1.0"
deepmerge "^4.2.2"
is-module "^1.0.0"
resolve "^1.19.0"

"@rollup/pluginutils@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==
dependencies:
"@types/estree" "0.0.39"
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@rollup/pluginutils@^4.1.1", "@rollup/pluginutils@^4.1.2":
version "4.1.2"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.1.2.tgz#ed5821c15e5e05e32816f5fb9ec607cdf5a75751"
Expand Down Expand Up @@ -2430,11 +2394,6 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.50.tgz#1e0caa9364d3fccd2931c3ed96fdbeaa5d4cca83"
integrity sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw==

"@types/estree@0.0.39":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==

"@types/express-serve-static-core@^4.17.18":
version "4.17.28"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz#c47def9f34ec81dc6328d0b1b5303d1ec98d86b8"
Expand Down Expand Up @@ -2558,13 +2517,6 @@
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc"
integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==

"@types/resolve@1.17.1":
version "1.17.1"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
integrity sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==
dependencies:
"@types/node" "*"

"@types/retry@^0.12.0":
version "0.12.1"
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.1.tgz#d8f1c0d0dc23afad6dc16a9e993a0865774b4065"
Expand Down Expand Up @@ -4612,11 +4564,6 @@ buffer@^5.5.0:
base64-js "^1.3.1"
ieee754 "^1.1.13"

builtin-modules@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.2.0.tgz#45d5db99e7ee5e6bc4f362e008bf917ab5049887"
integrity sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==

builtin-status-codes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
Expand Down Expand Up @@ -5386,11 +5333,6 @@ core-js@^2.4.0, core-js@^2.5.0, core-js@^2.6.5:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.12.tgz#d9333dfa7b065e347cc5682219d6f690859cc2ec"
integrity sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==

core-js@^3.1.3:
version "3.21.0"
resolved "https://registry.npmjs.org/core-js/-/core-js-3.21.0.tgz#f479dbfc3dffb035a0827602dd056839a774aa71"
integrity sha512-YUdI3fFu4TF/2WykQ2xzSiTQdldLB4KVuL9WeAy5XONZYt5Cun/fpQvctoKbCgvPhmzADeesTk/j2Rdx77AcKQ==

core-object@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/core-object/-/core-object-3.1.5.tgz#fa627b87502adc98045e44678e9a8ec3b9c0d2a9"
Expand Down Expand Up @@ -5650,11 +5592,6 @@ deep-is@^0.1.3, deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831"
integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==

deepmerge@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down Expand Up @@ -7131,11 +7068,6 @@ estree-walker@^0.6.1:
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362"
integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==

estree-walker@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700"
integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==

estree-walker@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
Expand Down Expand Up @@ -7356,7 +7288,7 @@ fast-diff@^1.1.2:
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==

fast-glob@^3.0.0, fast-glob@^3.0.3, fast-glob@^3.2.9:
fast-glob@^3.0.3, fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
Expand Down Expand Up @@ -8875,11 +8807,6 @@ is-language-code@^3.1.0:
dependencies:
"@babel/runtime" "^7.14.0"

is-module@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591"
integrity sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=

is-negative-zero@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.2.tgz#7bf6f03a28003b8b3965de3ac26f664d765f3150"
Expand Down Expand Up @@ -9792,7 +9719,7 @@ lodash.uniqby@^4.7.0:
resolved "https://registry.yarnpkg.com/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz#d99c07a669e9e6d24e1362dfe266c67616af1302"
integrity sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI=

lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@^4.7.0:
lodash@^4.17.10, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@^4.7.0:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -12187,7 +12114,7 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=

resolve@^1.10.0, resolve@^1.10.1, resolve@^1.11.1, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.4.0, resolve@^1.5.0, resolve@^1.8.1:
resolve@^1.10.0, resolve@^1.10.1, resolve@^1.11.1, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.20.0, resolve@^1.4.0, resolve@^1.5.0, resolve@^1.8.1:
version "1.21.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.21.0.tgz#b51adc97f3472e6a5cf4444d34bc9d6b9037591f"
integrity sha512-3wCbTpk5WJlyE4mSOtDLhqQmGFi0/TD9VPwmiolnk8U0wRgMEktqCXd3vy5buTO3tljvalNvKrjHEfrd2WpEKA==
Expand Down Expand Up @@ -12282,15 +12209,6 @@ rollup-plugin-delete@^2.0.0:
dependencies:
del "^5.1.0"

rollup-plugin-multi-input@1.3.1:
version "1.3.1"
resolved "https://registry.npmjs.org/rollup-plugin-multi-input/-/rollup-plugin-multi-input-1.3.1.tgz#07b903b618c005871fea1bd0c4efae7d1aac4fa1"
integrity sha512-bPsxHR6dUney7zsCAAlfkq7lbuy5xph2CvUstSv88oqhtRiLWXwVjiA1Gb4HVjC6I9sJI2eZeQlozXa+GXJKDA==
dependencies:
core-js "^3.1.3"
fast-glob "^3.0.0"
lodash "^4.17.11"

rollup-plugin-ts@2.0.5:
version "2.0.5"
resolved "https://registry.npmjs.org/rollup-plugin-ts/-/rollup-plugin-ts-2.0.5.tgz#35a23bbcd24deb8c5594e89a8fb1a7cdab3fa5c4"
Expand Down

0 comments on commit 125700f

Please sign in to comment.