Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #340 from saguijs/html-loader
Browse files Browse the repository at this point in the history
Add support to load HTML files 🌎
  • Loading branch information
pirelenito authored Apr 23, 2017
2 parents c6e3d84 + 2533cdc commit 9e70dbe
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The development server out-of-the-box has live reloading and **hot-module replac
Sagui uses [Webpack](http://webpack.github.io/) as its underlying bundling tool. The biggest feature that Webpack provides is that everything is a module. Sagui supports the following module types by default:

- Fonts (`.woff`, `.woff2`, `.ttf`, `.eot`, `.otf`)
- HTML (`.html`)
- Images (`.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`)
- JavaScript (`.js`, `.es6`, `.jsx`) via [Babel]((http://babeljs.io/docs/learn-es2015/))
- JSON
Expand Down Expand Up @@ -345,6 +346,7 @@ module.exports = {
Possible values:

- `font`
- `html`
- `image`
- `javaScript`
- `style`
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"flow-bin": "0.43.1",
"fs-extra": "^2.1.2",
"happypack": "^3.0.3",
"html-loader": "^0.4.5",
"html-webpack-plugin": "^2.28.0",
"jasmine-core": "^2.5.2",
"karma": "^1.6.0",
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/project-content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import cssModule from './css-module.css'
import scssModule from './css-module.scss'
import './react-component'
import './object-rest'
import './page.html'

console.log(text, cssModule.batata, scssModule.batata)
11 changes: 11 additions & 0 deletions spec/fixtures/project-content/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
20 changes: 20 additions & 0 deletions src/configure-webpack/loaders/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fileExtensions from '../../file-extensions'

export default {
name: 'html',
configure ({ optimize }) {
return {
module: {
rules: [
{
test: fileExtensions.test.HTML,
loader: 'html-loader',
options: {
minimize: optimize
}
}
]
}
}
}
}
11 changes: 11 additions & 0 deletions src/configure-webpack/loaders/html.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect } from 'chai'

import loader from './html'

describe('html', function () {
it('should have a html loader', function () {
const webpackConfig = loader.configure({})
const webpackLoader = webpackConfig.module.rules.find((loader) => loader.loader === 'html-loader')
expect(webpackLoader.test).eql(/\.html$/)
})
})
2 changes: 2 additions & 0 deletions src/configure-webpack/loaders/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import merge from 'webpack-merge'

import font from './font'
import html from './html'
import image from './image'
import javaScript from './javascript'
import style from './style'
Expand All @@ -10,6 +11,7 @@ import yaml from './yaml'

const loaders = [
font,
html,
image,
javaScript,
style,
Expand Down
2 changes: 1 addition & 1 deletion src/configure-webpack/loaders/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('buildLoadersConfig', function () {
it('should allow disabling all loaders', () => {
const saguiConfig = {
...baseSaguiConfig,
disableLoaders: ['font', 'image', 'javaScript', 'json', 'style', 'txt', 'video', 'yaml']
disableLoaders: ['font', 'html', 'image', 'javaScript', 'json', 'style', 'txt', 'video', 'yaml']
}

const config = buildLoadersConfig(saguiConfig)
Expand Down
1 change: 1 addition & 0 deletions src/file-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
test: {
CSS: /\.css$/,
EOT: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
HTML: /\.html$/,
IMAGE: /\.(png|jpg|jpeg|gif|svg)$/,
JAVASCRIPT: /\.(jsx?|es6)$/,
JSON: /\.(json)$/,
Expand Down

0 comments on commit 9e70dbe

Please sign in to comment.