-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6548098
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
.DS_Store | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"tabWidth": 4, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Next.js + Html | ||
|
||
Import `.html` files as strings in your Next.js project | ||
|
||
## Installation | ||
|
||
``` | ||
npm install --save @blunck/next-html | ||
``` | ||
|
||
## Usage | ||
|
||
Create a `next.config.js` in your project | ||
|
||
```js | ||
// next.config.js | ||
const withHtml = require('@blunck/next-html')() | ||
module.exports = withHtml() | ||
``` | ||
|
||
You can now import `.html` files as strings | ||
|
||
```js | ||
import foo from './foo.html' | ||
|
||
export default () => <div dangerouslySetInnerHTML={{ __html: foo }} /> | ||
``` | ||
|
||
### With `html-loader` options | ||
|
||
Optionally you can provide [html-loader](https://github.com/webpack-contrib/html-loader) options | ||
|
||
```js | ||
// next.config.js | ||
const withHtml = require('@blunck/next-html')({ | ||
minimize: true, | ||
conservativeCollapse: false | ||
}) | ||
module.exports = withHtml() | ||
``` | ||
|
||
### Configuring Next.js | ||
|
||
Optionally you can add your custom Next.js configuration as parameter | ||
|
||
```js | ||
// next.config.js | ||
const withHtml = require('@blunck/next-html')() | ||
module.exports = withHtml({ | ||
webpack(config, options) { | ||
return config | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const defaultHtmlLoaderOptions = { | ||
minimize: true, | ||
conservativeCollapse: false | ||
} | ||
|
||
module.exports = htmlLoaderOptions => (nextConfig = {}) => { | ||
htmlLoaderOptions = htmlLoaderOptions || defaultHtmlLoaderOptions | ||
|
||
return Object.assign({}, nextConfig, { | ||
webpack(config, options) { | ||
config.module.rules.push({ | ||
test: /\.html$/, | ||
loader: 'html-loader', | ||
options: htmlLoaderOptions | ||
}) | ||
|
||
if (typeof nextConfig.webpack === 'function') { | ||
return nextConfig.webpack(config, options) | ||
} | ||
|
||
return config | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@blunck/next-html", | ||
"version": "1.0.0", | ||
"description": "Import `.html` files as strings in your Next.js project", | ||
"main": "index.js", | ||
"repository": "alexblunck/next-html", | ||
"keywords": [ | ||
"nextjs", | ||
"html-loader", | ||
"html" | ||
], | ||
"author": "Alexander Blunck", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/alexblunck/next-html/issues" | ||
}, | ||
"homepage": "https://github.com/alexblunck/next-html#readme", | ||
"dependencies": { | ||
"html-loader": "0.5.5" | ||
} | ||
} |