Skip to content

Commit 2bc9c48

Browse files
Add Vitejs ⚡️
1 parent 5efafeb commit 2bc9c48

15 files changed

+233
-5313
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# LitElement starter site
2-
## Litelement + Typescript + Webpack
2+
3+
this project has a ready to production configuration.
4+
5+
## Litelement + Typescript + Vitejs + Rollup.js
36
This project includes a **VERY sample site** to start using LitElement with TypeScript (you can also use JS).
47

58
The project tries to have the same structure as an `Android project`. The idea is that it feels familiar and we develop with a standard (or as similar as possible)
@@ -23,21 +26,19 @@ yarn
2326

2427
## 🚀 Start
2528

26-
This sample uses the Babel and webpack to produce JavaScript that runs in modern browsers.
29+
This sample uses the `Babel` and `esbuild` with `Vitejs` to produce JavaScript that runs in modern browsers.
2730

2831
### Dev Server
2932

30-
This sample uses [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) for previewing the project without additional build steps. `webpack-dev-server` handles resolving Node-style "bare" import specifiers, which aren't supported in browsers. It also automatically transpiles Typescript to JavaScript files.
33+
This sample uses [Vitejs](https://vitejs.dev/) for previewing the project without additional build steps. `Vitejs` handles resolving Node-style "bare" import specifiers, which aren't supported in browsers. It also automatically transpiles Typescript to JavaScript files.
3134

32-
There is a development HTML file located at `src/index.html` that you can view at http://localhost:8000.
35+
There is a development HTML file located at `index.html` that you can view at http://localhost:8000.
3336

3437
To `build` and `run` the JavaScript version of your component (include watcher):
3538

3639
```bash
3740
npm run dev
38-
```
39-
or
40-
```bash
41+
# or
4142
yarn dev
4243
```
4344

src/index.html renamed to index.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535

3636
<!-- Homescreen icons -->
3737
<link rel="apple-touch-startup-image" href="res/drawable/favicon.png" />
38-
<link rel="apple-touch-icon" href="/favicon.png" />
38+
<link rel="apple-touch-icon" href="/res/drawable/favicon.png" />
3939

4040
<!-- Tile icon for Windows 8 (144x144 + tile color) -->
4141
<meta name="msapplication-TileImage" content="res/drawable/favicon.png" />
4242
<meta name="msapplication-TileColor" content="#16478e" />
4343
<meta name="msapplication-tap-highlight" content="no" />
4444

4545
<!-- See https://goo.gl/OOhYW5 -->
46-
<link rel="shortcut icon" href="/res/drawable/favicon.png" />
46+
<link rel="shortcut icon" type="image/svg+xml" href="/res/drawable/favicon.svg" />
4747
<link rel="manifest" href="manifest.json" />
4848

4949
<style>
@@ -72,7 +72,14 @@
7272
<noscript>
7373
Please enable JavaScript to view this website. v3.5.8
7474
</noscript>
75-
<script src="./node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
75+
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
76+
<script
77+
src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/6.8.3/system.min.js"
78+
integrity="sha512-dGQpe9Hb1dXjYT7TSrTS6qnRmzrhY9wsyRtN6BR2R+XgiXf5cpgvWVGPWptrarkfoldzpIkl7adWEddhoKsX6A=="
79+
crossorigin="anonymous"
80+
referrerpolicy="no-referrer"
81+
></script>
82+
<script type="module" src="/src/lit-app.ts"></script>
7683
</body>
7784

7885
</html>

package.json

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,36 @@
44
"version": "1.0.0",
55
"main": "index.html",
66
"scripts": {
7-
"build": "webpack --mode production",
8-
"dev": "webpack serve --mode development"
7+
"dev": "vite",
8+
"build": "vite build"
99
},
1010
"dependencies": {
11-
"@babel/plugin-proposal-export-default-from": "^7.12.13",
12-
"@conectate/ct-lit": "^3.1.0",
13-
"@conectate/ct-router": "^3.1.0",
11+
"@conectate/ct-lit": "^3.2.1",
12+
"@conectate/ct-router": "^3.2.1",
1413
"@webcomponents/webcomponentsjs": "^2.5.0",
15-
"lit": "^2.0.0-rc.1"
14+
"lit": "^2.0.0-rc.2"
1615
},
1716
"devDependencies": {
18-
"@babel/core": "^7.14.0",
19-
"@babel/plugin-proposal-logical-assignment-operators": "^7.13.8",
20-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8",
21-
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
17+
"@babel/core": "^7.14.3",
18+
"@babel/plugin-proposal-decorators": "^7.14.2",
19+
"@babel/plugin-proposal-export-default-from": "^7.12.13",
2220
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
2321
"@babel/plugin-syntax-import-meta": "^7.10.4",
24-
"@babel/plugin-transform-async-to-generator": "^7.13.0",
25-
"@babel/plugin-transform-runtime": "^7.13.15",
26-
"@babel/preset-env": "^7.14.1",
27-
"@firebase/app-types": "^0.6.1",
22+
"@babel/preset-env": "^7.14.4",
23+
"@firebase/app-types": "^0.6.2",
24+
"@rollup/plugin-babel": "^5.3.0",
25+
"@rollup/plugin-node-resolve": "^13.0.0",
2826
"babel-loader": "^8.2.2",
2927
"babel-plugin-bundled-import-meta": "^0.3.2",
3028
"babel-plugin-template-html-minifier": "^4.1.0",
31-
"clean-webpack-plugin": "^4.0.0-alpha.0",
32-
"copy-webpack-plugin": "5.0.3",
33-
"html-webpack-plugin": "^5.3.1",
34-
"prettier": "^2.2.1",
35-
"svg-inline-loader": "^0.8.0",
36-
"ts-loader": "^9.1.2",
37-
"typescript": "^4.2.4",
38-
"webpack": "^5.36.2",
39-
"webpack-bundle-analyzer": "^4.4.1",
40-
"webpack-cli": "^4.6.0",
41-
"webpack-dev-server": "^3.11.2"
29+
"prettier": "^2.3.0",
30+
"rollup-plugin-copy": "^3.4.0",
31+
"rollup-plugin-minify-html-literals": "^1.2.6",
32+
"rollup-plugin-summary": "^1.3.0",
33+
"rollup-plugin-terser": "^7.0.2",
34+
"svg-inline-loader": "^0.8.2",
35+
"ts-loader": "^9.2.2",
36+
"typescript": "^4.3.2",
37+
"vite": "^2.3.6"
4238
}
43-
}
39+
}

res/drawable/favicon.png

-49.9 KB
Binary file not shown.

res/drawable/favicon.svg

Lines changed: 16 additions & 0 deletions
Loading

res/index.universal.html

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!DOCTYPE html>
2+
<html lang="es">
3+
4+
<head>
5+
<!-- Material - Responsive -->
6+
<meta charset="utf-8" />
7+
<title>LitElement Starter Project</title>
8+
<base href="/" />
9+
<meta name="description" content="Template for LitElement Starter Project" />
10+
<meta name=" theme-color" content="#16478e" />
11+
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1" />
12+
<meta name="robots" content="index, follow" />
13+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=40" />
14+
<!--<meta name="apple-itunes-app" content="app-id=1093787284" />-->
15+
<link rel="canonical" href="https://github.com/conectate/lit-element-starter" id="canonical" />
16+
17+
18+
<!-- Facebook’s Open Graph -->
19+
<meta property="og:type" content="website" />
20+
<meta property="og:url" content="https://github.com/conectate/lit-element-starter" />
21+
<meta property="og:title" content="LitElement Starter Project" />
22+
<meta property="og:site_name" content="LitElement Starter Project" />
23+
<meta property="og:description" content="Template for LitElement Starter Project" />
24+
<meta property=" og:image" content="/res/drawable/og/default.png" />
25+
<!-- twitter -->
26+
<meta name="twitter:card" content="app" />
27+
<meta name="twitter:title" content="LitElement Starter Project" />
28+
<meta name="twitter:description" content="Template for LitElement Starter Project" />
29+
<meta name=" twitter:image" content="/res/drawable/og/default.png" />
30+
31+
<!-- Add to homescreen for Safari on iOS -->
32+
<meta name="apple-mobile-web-app-capable" content="yes" />
33+
<meta name="apple-mobile-web-app-status-bar-style" content="#16478e" />
34+
<meta name="apple-mobile-web-app-title" content="LitElement Starter Project" />
35+
36+
<!-- Homescreen icons -->
37+
<link rel="apple-touch-startup-image" href="res/drawable/favicon.png" />
38+
<link rel="apple-touch-icon" href="/favicon.png" />
39+
40+
<!-- Tile icon for Windows 8 (144x144 + tile color) -->
41+
<meta name="msapplication-TileImage" content="res/drawable/favicon.png" />
42+
<meta name="msapplication-TileColor" content="#16478e" />
43+
<meta name="msapplication-tap-highlight" content="no" />
44+
45+
<!-- See https://goo.gl/OOhYW5 -->
46+
<link rel="shortcut icon" href="/res/drawable/favicon.png" />
47+
<link rel="manifest" href="manifest.json" />
48+
49+
<style>
50+
html {
51+
height: 100%;
52+
width: 100%;
53+
max-height: 100%;
54+
max-width: 100%;
55+
}
56+
57+
body,
58+
html {
59+
position: relative;
60+
margin: 0;
61+
padding: 0;
62+
font-size: 14px;
63+
background: var(--color-background, #fff);
64+
height: 100%;
65+
font-family: 'Roboto', sans-serif !important;
66+
}
67+
</style>
68+
</head>
69+
70+
<body>
71+
<lit-app></lit-app>
72+
<noscript>
73+
Please enable JavaScript to view this website. v3.5.8
74+
</noscript>
75+
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
76+
<script
77+
src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/6.8.3/system.min.js"
78+
integrity="sha512-dGQpe9Hb1dXjYT7TSrTS6qnRmzrhY9wsyRtN6BR2R+XgiXf5cpgvWVGPWptrarkfoldzpIkl7adWEddhoKsX6A=="
79+
crossorigin="anonymous"
80+
referrerpolicy="no-referrer"
81+
></script>
82+
<script>
83+
System.import('/app.bundle.js');
84+
</script>
85+
</body>
86+
87+
</html>
File renamed without changes.

res/service-worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("development");

src/home/activities/home-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CtLit, html, property, customElement, css } from '@conectate/ct-lit';
2-
import { strings } from '../../../res/values/strings';
2+
import { strings } from '../../xconfig/strings';
33

44
@customElement('home-app')
55
export class HomeApp extends CtLit {

src/lit-app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import './base/app-router';
22
import AppLocalStorage from './base/app-localstorage';
3-
import { loadLang } from '../res/values/strings';
3+
import { loadLang } from './xconfig/strings';
44
import { css, CtLit, customElement, html } from '@conectate/ct-lit';
5-
import { property, query, queryAll, queryAssignedNodes, queryAsync, state, state as internalProperty } from 'lit/decorators.js';
5+
import { property } from 'lit/decorators.js';
66
import { injectTheme, Theme } from './base/styles/default-theme';
77

88
@customElement('lit-app')
File renamed without changes.
File renamed without changes.

vite.config.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { RollupBabelInputPluginOptions, babel } from '@rollup/plugin-babel';
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import copy from 'rollup-plugin-copy';
4+
import minifyHTML from 'rollup-plugin-minify-html-literals';
5+
import summary from 'rollup-plugin-summary';
6+
import { terser } from 'rollup-plugin-terser';
7+
import { defineConfig } from 'vite';
8+
9+
import app from './package.json';
10+
11+
const babelConfig: RollupBabelInputPluginOptions = {
12+
babelHelpers: 'bundled',
13+
plugins: [
14+
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
15+
'@babel/plugin-syntax-dynamic-import',
16+
'@babel/plugin-syntax-import-meta',
17+
'@babel/plugin-proposal-export-default-from'
18+
],
19+
babelrc: false,
20+
presets: [['@babel/preset-env', { targets: { chrome: process.env.NODE_ENV == 'development' ? '90' : '55' }, debug: true }]]
21+
};
22+
23+
const copyConfig = {
24+
targets: [
25+
{ src: 'node_modules/@webcomponents', dest: './build/node_modules' },
26+
{ src: 'res/index.universal.html', dest: 'build', rename: 'index.bak.html' },
27+
{ src: 'res/manifest.json', dest: './build' },
28+
{ src: 'res', dest: 'build' }
29+
]
30+
};
31+
let development = process.env.NODE_ENV != 'production';
32+
33+
console.log('process.env.NODE_ENV ', process.env.NODE_ENV);
34+
// https://vitejs.dev/config/
35+
export default (opts: any) => {
36+
return defineConfig({
37+
server: {
38+
port: 8000,
39+
fsServe: {
40+
root: '/'
41+
}
42+
},
43+
define: {
44+
'process.env.NODE_ENV': JSON.stringify(development ? 'development' : 'production'),
45+
'process.env.VERSION': JSON.stringify(app.version)
46+
},
47+
plugins: [],
48+
build: {
49+
target: 'chrome55',
50+
assetsInlineLimit: 100000,
51+
// "outDir": "build",
52+
rollupOptions: {
53+
input: {
54+
app: './src/lit-app.ts'
55+
},
56+
// input: ['src/my-element.ts'],
57+
// Specifies two JS output configurations, modern and legacy, which the HTML plugin will
58+
// automatically choose between; the legacy build is compiled to ES5
59+
// and SystemJS modules
60+
output: {
61+
// Legacy JS bundles (ES5 compilation and SystemJS module output)
62+
format: 'systemjs',
63+
chunkFileNames: `${process.env.NODE_ENV == 'development' ? '[name].' : 'c.'}[hash].js`,
64+
entryFileNames: '[name].bundle.js',
65+
dir: 'build'
66+
},
67+
plugins: [
68+
// Minify HTML template literals
69+
minifyHTML(),
70+
babel(babelConfig),
71+
// Resolve bare module specifiers to relative paths
72+
resolve(),
73+
74+
// Minify JS
75+
terser({
76+
module: true
77+
}),
78+
// @ts-ignore Print bundle summary
79+
summary(),
80+
copy(copyConfig)
81+
],
82+
preserveEntrySignatures: false
83+
}
84+
}
85+
});
86+
};

0 commit comments

Comments
 (0)