Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Commit 0aeed36

Browse files
committed
Add fallback bundle
1 parent 2f238c6 commit 0aeed36

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

src/html-plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ const htmlTemplate = ({
3030
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
3131
<title>Document</title>
3232
${entryStyles.map(printStyle).join('\n ')}
33-
${entryScripts.map(printScript).join('\n ')}
3433
</head>
3534
<body>
35+
<script nomodule async src="/nomodule.js"></script>
36+
${entryScripts.map(printScript).join('\n ')}
3637
</body>
3738
</html>`
3839

src/index.ts

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,55 @@ export const createRollupConfig = (
2727
},
2828
}),
2929
]
30-
const config: RollupConfig = {
31-
input: ['src/index.tsx'],
32-
experimentalCodeSplitting: true,
33-
output: {
34-
dir: 'dist',
35-
format: 'es',
30+
const config: RollupConfig[] = [
31+
{
32+
input: ['src/index.tsx'],
33+
experimentalCodeSplitting: true,
34+
output: {
35+
dir: 'dist',
36+
format: 'es',
37+
},
38+
plugins: [
39+
postcss({
40+
extract: 'dist/index.css',
41+
minimize: true,
42+
modules: {
43+
generateScopedName: development
44+
? '[local]-[hash:base64:4]'
45+
: '[hash:base64:4]',
46+
},
47+
}),
48+
babel({ babelrc: false, ...babelConfig }),
49+
nodeResolve({
50+
jsnext: true,
51+
extensions: ['.mjs', '.js', '.json', '.ts', '.tsx', '.css'],
52+
}),
53+
htmlPlugin({ routes, entryStyles: ['index.css'] }),
54+
].concat(development ? [] : prodPlugins),
55+
},
56+
{
57+
input: 'src/index.tsx',
58+
output: {
59+
file: 'dist/nomodule.js',
60+
name: 'nomodule',
61+
format: 'iife',
62+
},
63+
plugins: [
64+
postcss({
65+
extract: false,
66+
modules: {
67+
generateScopedName: development
68+
? '[local]-[hash:base64:4]'
69+
: '[hash:base64:4]',
70+
},
71+
}),
72+
babel({ babelrc: false, ...babelConfig }),
73+
nodeResolve({
74+
jsnext: true,
75+
extensions: ['.mjs', '.js', '.json', '.ts', '.tsx', '.css'],
76+
}),
77+
].concat(development ? [] : prodPlugins),
3678
},
37-
plugins: [
38-
postcss({
39-
extract: 'dist/index.css',
40-
minimize: true,
41-
modules: {
42-
generateScopedName: development
43-
? '[local]-[hash:base64:4]'
44-
: '[hash:base64:4]',
45-
},
46-
}),
47-
babel({ babelrc: false, ...babelConfig }),
48-
nodeResolve({
49-
jsnext: true,
50-
extensions: ['.mjs', '.js', '.json', '.ts', '.tsx', '.css'],
51-
}),
52-
htmlPlugin({ routes, entryStyles: ['index.css'] }),
53-
].concat(development ? [] : prodPlugins),
54-
}
79+
]
5580
return config
5681
}

0 commit comments

Comments
 (0)