-
-
Notifications
You must be signed in to change notification settings - Fork 372
Migrate to Webpack 3.x #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c198422
d028fd8
35b14c2
7f9dd77
0b9fc0e
32d2979
e9889d0
38dd7de
7729b5a
aa8ab49
1085f21
a954fd6
02e2616
6a5013e
8fa1276
7ee95b6
0349b2e
0656348
4b3a792
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { resolve } from 'path'; | ||
| import { existsSync } from 'fs'; | ||
| import HtmlWebpackExcludeAssetsPlugin from 'html-webpack-exclude-assets-plugin'; | ||
| import ScriptExtHtmlWebpackPlugin from 'script-ext-html-webpack-plugin'; | ||
| import HtmlWebpackPlugin from 'html-webpack-plugin'; | ||
| import { readJson } from './webpack-base-config'; | ||
| import prerender from './prerender'; | ||
|
|
||
| export default function (config) { | ||
| const { cwd, dest, isProd, src } = config; | ||
|
|
||
| const htmlWebpackConfig = ({ url, title }) => ({ | ||
| filename: resolve(dest, url.substring(1), 'index.html'), | ||
| template: `!!ejs-loader!${config.template || resolve(__dirname, '../../resources/template.html')}`, | ||
| minify: isProd && { | ||
| collapseWhitespace: true, | ||
| removeScriptTypeAttributes: true, | ||
| removeRedundantAttributes: true, | ||
| removeStyleLinkTypeAttributes: true, | ||
| removeComments: true | ||
| }, | ||
| favicon: existsSync(resolve(src, 'assets/favicon.ico')) ? 'assets/favicon.ico' : resolve(__dirname, '../../resources/favicon.ico'), | ||
| manifest: config.manifest, | ||
| inject: true, | ||
| compile: true, | ||
| preload: config.preload===true, | ||
| title: title || config.title || config.manifest.name || config.manifest.short_name || (config.pkg.name || '').replace(/^@[a-z]\//, '') || 'Preact App', | ||
| excludeAssets: [/(bundle|polyfills)(\..*)?\.js$/], | ||
| config, | ||
| ssr(params) { | ||
| return config.prerender ? prerender({ cwd, dest, src }, { ...params, url }) : ''; | ||
| } | ||
| }); | ||
|
|
||
| const pages = readJson(resolve(cwd, config.prerenderUrls || '')) || [{ url: '/' }]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should't this be using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea maybe we should do it in a separate PR. Basically, the whole "subdirectory" stuff is something we should fix. But yea, let's keep it separate. |
||
|
|
||
| return pages.map(htmlWebpackConfig).map(conf => new HtmlWebpackPlugin(conf)).concat([ | ||
| new HtmlWebpackExcludeAssetsPlugin(), | ||
| new ScriptExtHtmlWebpackPlugin({ | ||
| // inline: 'bundle.js', | ||
| defaultAttribute: 'defer' | ||
| }) | ||
| ]); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
letneccesary here? Can this be aconst?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@developit prefers
letfor most things. I broke the rule & usedconsta few times to be emphatic.