Skip to content

Commit 1db4951

Browse files
authored
Improve JS bundling (#281)
- Only import modules on the pages they are actually needed. Previously we had a global.js that had way more than was needed on most pages. - Choose some nicer names for the common Rollup chunks. Now we'll have a "lit.js" chunk that's just lit. I expect people will look for this in devtools, and it's nice to have it be there and be the minimal size. - Re-organize TypeScript files. - Unified/much simpler rollup config. - Don't use module + async, it's more aggressive. - Change rollup output to rollupout/ instead of writing directly into _site -- this interferes with the dev cycle less. Also: - Fix API docs import styling - Switch to new Google SPDX license headers
1 parent 8283b42 commit 1db4951

40 files changed

+281
-464
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ packages/*/index.d.ts.map
1010

1111
packages/lit-dev-content/_site
1212
packages/lit-dev-content/_dev
13-
packages/lit-dev-content/site/_includes/js/
1413
packages/lit-dev-content/playground-plugin
14+
packages/lit-dev-content/rollupout
1515

1616
packages/lit-dev-api/lit/
1717
packages/lit-dev-api/api-data/**/*

LICENSE

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2020 Google LLC. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package-lock.json

+24-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"check-links:internal": "wait-on tcp:8080 && blc http://localhost:8080 --exclude '*TODO_HREF' --exclude 'http://localhost:8080/api/*' --recursive --exclude-external --ordered",
1818
"check-links:external": "wait-on tcp:8080 && blc http://localhost:8080 --exclude '*TODO_HREF' --exclude 'http://localhost:8080/api/*' --exclude 'http://localhost:8000/dev/' --exclude 'https://github.com/Polymer/internal*' --exclude 'https://github.com/PolymerLabs/lit.dev*' --exclude 'https://www.npmjs.com/*' --get --recursive --exclude-internal --host-requests 1"
1919
},
20-
"author": "",
20+
"author": "Google LLC",
2121
"license": "BSD-3-Clause",
2222
"devDependencies": {
2323
"broken-link-checker": "^0.7.8",

packages/lit-dev-content/.eleventy.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,24 @@ module.exports = function (eleventyConfig) {
4040
eleventyConfig.addPlugin(playgroundPlugin);
4141
if (!DEV) {
4242
// In dev mode, we symlink these directly to source.
43+
eleventyConfig.addPassthroughCopy({'rollupout/': './js/'});
4344
eleventyConfig.addPassthroughCopy('site/css');
4445
eleventyConfig.addPassthroughCopy('site/images');
4546
eleventyConfig.addPassthroughCopy('samples');
47+
eleventyConfig.addPassthroughCopy({
48+
'node_modules/playground-elements/playground-typescript-worker.js':
49+
'./js/playground-typescript-worker.js',
50+
});
51+
eleventyConfig.addPassthroughCopy({
52+
'node_modules/playground-elements/playground-service-worker.js':
53+
'./js/playground-service-worker.js',
54+
});
55+
eleventyConfig.addPassthroughCopy({
56+
'node_modules/playground-elements/playground-service-worker-proxy.html':
57+
'./js/playground-service-worker-proxy.html',
58+
});
4659
}
4760
eleventyConfig.addPassthroughCopy('api/**/*');
48-
eleventyConfig.addPassthroughCopy({
49-
'node_modules/playground-elements/playground-typescript-worker.js':
50-
'./js/playground-typescript-worker.js',
51-
});
52-
eleventyConfig.addPassthroughCopy({
53-
'node_modules/playground-elements/playground-service-worker.js':
54-
'./js/playground-service-worker.js',
55-
});
56-
eleventyConfig.addPassthroughCopy({
57-
'node_modules/playground-elements/playground-service-worker-proxy.html':
58-
'./js/playground-service-worker-proxy.html',
59-
});
6061

6162
eleventyConfig.addWatchTarget('../lit-dev-api/api-data');
6263

@@ -236,16 +237,16 @@ ${content}
236237

237238
/**
238239
* Inline the Rollup-bundled version of a JavaScript module. Path is relative
239-
* to ./site/_includes/js/ directory (which is where Rollup output goes).
240+
* to ./rollupout.
240241
*
241-
* In dev mode, instead directly import the module relative from ./lib/ (which
242-
* is where TypeScript output goes).
242+
* In dev mode, instead directly import the module, which has already been
243+
* symlinked directly to the TypeScript output directory.
243244
*/
244245
eleventyConfig.addShortcode('inlinejs', (path) => {
245246
if (DEV) {
246-
return `<script type="module" src="/lib/${path}"></script>`;
247+
return `<script type="module" src="/js/${path}"></script>`;
247248
}
248-
const script = fsSync.readFileSync(`site/_includes/js/${path}`, 'utf8');
249+
const script = fsSync.readFileSync(`rollupout/${path}`, 'utf8');
249250
return `<script type="module">${script}</script>`;
250251
});
251252

@@ -301,11 +302,11 @@ ${content}
301302
path.join(__dirname, '_dev', 'samples')
302303
);
303304

304-
// Symlink lib -> _dev/lib. This lets us directly reference tsc outputs in
305+
// Symlink lib -> _dev/js. This lets us directly reference tsc outputs in
305306
// dev mode, instead of the Rollup bundles we use for production.
306307
await symlinkForce(
307308
path.join(__dirname, 'lib'),
308-
path.join(__dirname, '_dev', 'lib')
309+
path.join(__dirname, '_dev', 'js')
309310
);
310311
} else {
311312
// Inline all Playground project files directly into their manifests, to

0 commit comments

Comments
 (0)