Skip to content

Commit e5c0137

Browse files
committed
✨ Compile SystemJS output to ES5
This is currently done less optimally than possible but works alright.
1 parent af15f11 commit e5c0137

5 files changed

Lines changed: 487 additions & 29 deletions

File tree

.babelrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
{
2-
"sourceType": "module"
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": "> 1%, last 2 versions, Firefox ESR, not dead"
7+
}
8+
}]
9+
],
10+
"plugins": [
11+
"syntax-dynamic-import"
12+
]
313
}

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"redux": "^4.0.0",
3333
"redux-devtools-extension": "^2.13.2",
3434
"redux-saga": "^0.16.0",
35+
"regenerator-runtime": "^0.11.1",
3536
"reselect": "^3.0.1",
3637
"systemjs": "^0.21.3"
3738
},
@@ -40,11 +41,14 @@
4041
"@polymer/paper-dialog": "^3.0.0-pre.12",
4142
"@types/lodash-es": "^4.17.0",
4243
"@types/spotify-web-playback-sdk": "^0.1.1",
44+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
45+
"babel-preset-env": "^1.7.0",
4346
"bundlesize": "^0.17.0",
4447
"connect-history-api-fallback": "^1.5.0",
4548
"firebase-bolt": "^0.8.2",
4649
"raven-js": "^3.24.0",
4750
"rollup": "^0.59.1",
51+
"rollup-plugin-babel": "^3.0.4",
4852
"rollup-plugin-babel-minify": "^5.0.0",
4953
"rollup-plugin-browsersync": "^0.2.6",
5054
"rollup-plugin-commonjs": "^9.1.0",
@@ -54,15 +58,17 @@
5458
"rollup-plugin-node-resolve": "^3.0.0",
5559
"rollup-plugin-replace": "^2.0.0",
5660
"rollup-plugin-typescript2": "^0.14.0",
61+
"rollup-plugin-uglify": "^4.0.0",
5762
"spotify-web-api-js": "^0.24.0",
5863
"tslint": "^5.8.0",
5964
"typescript": "^2.6.2",
60-
"typescript-lit-html-plugin": "^0.2.0"
65+
"typescript-lit-html-plugin": "^0.2.0",
66+
"uglify-js": "^3.3.28"
6167
},
6268
"scripts": {
6369
"build": "NODE_ENV=production rollup -c && npm run copy",
6470
"check-size": "bundlesize",
65-
"copy": "mkdir -p build/node_modules/@webcomponents && cp -R node_modules/systemjs build/node_modules/systemjs && cp -R node_modules/@webcomponents/webcomponentsjs build/node_modules/@webcomponents/webcomponentsjs && cp -R assets/* build && cp src/index.html build",
71+
"copy": "mkdir -p build/node_modules/@webcomponents && cp -R node_modules/regenerator-runtime build/node_modules/regenerator-runtime && cp -R node_modules/systemjs build/node_modules/systemjs && cp -R node_modules/@webcomponents/webcomponentsjs build/node_modules/@webcomponents/webcomponentsjs && cp -R assets/* build && cp src/index.html build",
6672
"fix": "tslint -p tsconfig.json --fix",
6773
"lint": "tslint -p tsconfig.json",
6874
"prepare-env": "node prepare-env.js",

rollup.config.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import minifyLit from '@mraerino/rollup-plugin-minifyliterals';
12
import historyApi from 'connect-history-api-fallback';
23
import * as fs from 'fs';
4+
import babel from 'rollup-plugin-babel';
35
import minify from 'rollup-plugin-babel-minify';
6+
import browsersync from 'rollup-plugin-browsersync';
47
import cjs from 'rollup-plugin-commonjs';
58
import copy from 'rollup-plugin-copy';
69
import nodeBuiltins from 'rollup-plugin-node-builtins';
710
import nodeGlobals from 'rollup-plugin-node-globals';
811
import nodeResolve from 'rollup-plugin-node-resolve';
9-
import typescript from 'rollup-plugin-typescript2';
10-
import minifyLit from '@mraerino/rollup-plugin-minifyliterals';
11-
import browsersync from 'rollup-plugin-browsersync';
1212
import replace from 'rollup-plugin-replace';
13+
import typescript from 'rollup-plugin-typescript2';
14+
import { uglify } from 'rollup-plugin-uglify';
1315
import path from 'path';
1416

1517
const distTarget = './build';
@@ -24,7 +26,7 @@ if (!fs.existsSync('build')) {
2426
fs.mkdirSync('build');
2527
}
2628

27-
const plugins = [
29+
const basePlugins = [
2830
replace({
2931
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
3032
}),
@@ -58,45 +60,52 @@ const plugins = [
5860
typescript(),
5961
cjs(),
6062
nodeGlobals(), // WARNING: Never move above CommonJS plugin!
61-
isProduction ? minifyLit({
63+
isProduction && minifyLit({
6264
include: ['src/entry.ts', 'src/{components,views}/**', 'node_modules/@polymer/{paper,iron}-*/**'],
6365
includeExtension: ['.ts', '.js'],
6466
literals: false,
6567
htmlminifier: {
6668
minifyCSS: true, // causes some kind of trouble currently
6769
collapseWhitespace: true
6870
}
69-
}) : null,
70-
isProduction ? minify({ comments: false }) : null,
71-
!!process.env.ROLLUP_WATCH ? browsersync({
72-
port: process.env.PORT || 3000,
73-
server: {
74-
baseDir: dist(),
75-
middleware: [historyApi()]
76-
},
77-
open: false,
78-
ui: false
79-
}) : null,
80-
].filter(plugin => plugin !== null);
71+
}),
72+
];
8173

8274
const baseOptions = {
8375
input: [src('index.ts'), src('views/view-party.ts'), src('views/view-tv.ts')],
8476
experimentalDynamicImport: true,
8577
experimentalCodeSplitting: true,
86-
plugins,
8778
onwarn: err => console.error(err.toString()),
8879
watch: { include: 'src/**/*' },
8980
};
9081

9182
export default [{
9283
...baseOptions,
84+
plugins: [
85+
...basePlugins,
86+
// isProduction && minify({ comments: false }),
87+
!!process.env.ROLLUP_WATCH && browsersync({
88+
port: process.env.PORT || 3000,
89+
server: {
90+
baseDir: dist(),
91+
middleware: [historyApi()]
92+
},
93+
open: false,
94+
ui: false
95+
}),
96+
].filter(plugin => plugin),
9397
output: {
9498
dir: dist('module'),
9599
format: 'es',
96100
sourcemap: true,
97101
},
98102
}, {
99103
...baseOptions,
104+
plugins: [
105+
...basePlugins,
106+
babel(),
107+
isProduction && uglify(),
108+
].filter(plugin => plugin),
100109
output: {
101110
dir: dist('nomodule'),
102111
format: 'system',

src/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ <h1><span class="flash">⚡️</span> Oh, no! Unsupported Browser!</h1>
7272

7373
<!-- Polyfills -->
7474
<script class="scripts" src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
75+
<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"
76+
type="text/javascript"
77+
nomodule>
78+
</script>
79+
<script src="/node_modules/regenerator-runtime/runtime.js"
80+
type="text/javascript"
81+
class="scripts"
82+
nomodule>
83+
</script>
7584

7685
<!-- ES6 Module Code -->
7786
<script src="/module/index.ts.js" type="module" class="scripts"></script>

0 commit comments

Comments
 (0)