Skip to content

Commit

Permalink
Merge pull request #39 from umijs/support-config-html
Browse files Browse the repository at this point in the history
Support config html
  • Loading branch information
sorrycc authored Jan 2, 2018
2 parents c95b918 + e900c5a commit 459810e
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/af-webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "af-webpack",
"version": "0.13.6",
"version": "0.13.7",
"dependencies": {
"@babel/core": "7.0.0-beta.31",
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.31",
Expand Down Expand Up @@ -31,6 +31,7 @@
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"fork-ts-checker-webpack-plugin": "^0.2.9",
"html-webpack-plugin": "^2.30.1",
"inquirer": "^3.3.0",
"is-plain-object": "^2.0.4",
"is-root": "^1.0.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/af-webpack/src/getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import eslintFormatter from 'react-dev-utils/eslintFormatter';
import assert from 'assert';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import HTMLWebpackPlugin from 'html-webpack-plugin';
import { sync as resolveSync } from 'resolve';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import uglifyJSConfig from './defaultConfigs/uglifyJS';
Expand Down Expand Up @@ -319,7 +320,7 @@ export default function getConfig(opts = {}) {
]),
{
exclude: [
/\.html$/,
/\.html|ejs$/,
/\.json$/,
/\.(js|jsx|ts|tsx)$/,
/\.(css|less|scss|sass)$/,
Expand Down Expand Up @@ -446,6 +447,7 @@ export default function getConfig(opts = {}) {
}),
]
: []),
...(opts.html ? [new HTMLWebpackPlugin(opts.html)] : []),
new CaseSensitivePathsPlugin(),
new webpack.LoaderOptionsPlugin({
options: {
Expand Down
14 changes: 14 additions & 0 deletions packages/af-webpack/src/getUserConfig/configs/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import assert from 'assert';
import isPlainObject from 'is-plain-object';

export default function() {
return {
name: 'html',
validate(val) {
assert(
isPlainObject(val),
`The html config must be Plain Object, but got ${val}`,
);
},
};
}
5 changes: 5 additions & 0 deletions packages/af-webpack/test/fixtures/html/.webpackrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"html": {
"template": "index.ejs"
}
}
8 changes: 8 additions & 0 deletions packages/af-webpack/test/fixtures/html/expected/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

body {
background: red;
}

.a {
color: green;
}
13 changes: 13 additions & 0 deletions packages/af-webpack/test/fixtures/html/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test HTML</title>
<link href="index.css" rel="stylesheet"></head>
<body>

<script type="text/javascript" src="index.js"></script></body>
</html>
84 changes: 84 additions & 0 deletions packages/af-webpack/test/fixtures/html/expected/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__index_css__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__index_css___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__index_css__);

console.log(1);

/***/ }),
/* 1 */
/***/ (function(module, exports) {

// removed by extract-text-webpack-plugin

/***/ })
/******/ ]);
8 changes: 8 additions & 0 deletions packages/af-webpack/test/fixtures/html/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

body {
background: red;
}

.a {
color: green;
}
13 changes: 13 additions & 0 deletions packages/af-webpack/test/fixtures/html/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test HTML</title>
</head>
<body>

</body>
</html>
3 changes: 3 additions & 0 deletions packages/af-webpack/test/fixtures/html/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './index.css';

console.log(1);
4 changes: 2 additions & 2 deletions packages/umi-build-dev/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "umi-build-dev",
"version": "0.5.6",
"version": "0.5.7",
"dependencies": {
"address": "^1.0.3",
"af-webpack": "^0.13.6",
"af-webpack": "^0.13.7",
"antd": "^3.0.0",
"antd-mobile": "^2.0.0",
"chalk": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umi-test",
"version": "0.2.0",
"version": "0.2.1",
"bin": {
"umi-test": "./bin/umi-test.js"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/umi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umi",
"version": "1.0.0-beta.17",
"version": "1.0.0-beta.18",
"description": "A neat framework for building highly performance and cross-platform optimized web apps.",
"dependencies": {
"@babel/runtime": "7.0.0-beta.31",
Expand All @@ -14,9 +14,9 @@
"fastclick": "^1.0.6",
"history": "^4.7.2",
"query-string": "^5.0.0",
"umi-build-dev": "^0.5.6",
"umi-build-dev": "^0.5.7",
"umi-router": "^0.1.2",
"umi-test": "^0.2.0",
"umi-test": "^0.2.1",
"uppercamelcase": "^3.0.0",
"url": "^0.11.0",
"yargs-parser": "^7.0.0"
Expand Down

0 comments on commit 459810e

Please sign in to comment.