Skip to content
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

template参数失效问题 #38

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
66 changes: 66 additions & 0 deletions demo/auto-plugin-use-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 管理多个单页应用

`AutoWebPlugin` 可以自动管理多个单页应用。简单使用如下

```js
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { AutoWebPlugin } = require('../../index');

const autoWebPlugin = new AutoWebPlugin('./src/', {
ignorePages: ['ignore'],
template: './src/template.html',
outputPagemap: true,
});

module.exports = {
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
publicPath: 'https://cdn.cn/',
},
entry: autoWebPlugin.entry({
ie_polyfill: './src/ie_polyfill',
polyfill: './src/polyfill',
}),
optimization: {
splitChunks: {
minSize: 0,
cacheGroups: {
commons: {
chunks: 'initial',
name: 'common',
minChunks: 2,
},
},
},
},
module: {
rules: [
{
test: /\.css$/,
loader: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
autoWebPlugin,
],
};
```

以上配置会让`AutoWebPlugin`找出`./src/`目录下的所有目录,为每个目录生产一个 HTML 作为单页应用的入口。

* `ignorePages` 属性用了忽略名叫`ignore`的目录,不为这个目录生产 HTML 入口
* `template` 属性指出所有单页应用生产 HTML 入口时公用的 HTML 模版,模版语法和`WebPlugin`里一致。
* `outputPagemap` 属性用来输出一个叫`pagemap.json`的文件,里面存放了`AutoWebPlugin`找出的所有单页应用的名称和 URL 的映射关系。

`AutoWebPlugin`还支持很多配置选项,你可以[在这里看到](https://github.com/gwuhaolin/web-webpack-plugin/blob/master/lib/AutoWebPlugin.js#L33)。

更多关于`AutoWebPlugin`的资料可以参考以下文章:

* [webpack 原理与实战](https://github.com/gwuhaolin/blog/issues/4)
* [webpack2 终极优化](https://github.com/gwuhaolin/blog/issues/2)
4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist-js-prod/common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
color: red;
}

1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist-js-prod/common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist-js-prod/home.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: red;
}

20 changes: 20 additions & 0 deletions demo/auto-plugin-use-template/dist-js-prod/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<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">
<!--只在IE下注入ie_polyfill-->
<!--[if IE]><script src="https://cdn.cn/ie_polyfill.js"></script><![endif]-->
<!--开发模式下不注入polyfill-->
<!--<script src="polyfill?_dist&amp;_inline"></script>-->
<link rel="stylesheet" href="https://cdn.cn/common.css">
<link rel="stylesheet" href="https://cdn.cn/home.css">
</head>
<body>
<script src="https://cdn.cn/common.js"></script>

<script src="https://cdn.cn/home.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist-js-prod/home.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist-js-prod/ie_polyfill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist-js-prod/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: blue;
}

20 changes: 20 additions & 0 deletions demo/auto-plugin-use-template/dist-js-prod/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<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">
<!--只在IE下注入ie_polyfill-->
<!--[if IE]><script src="https://cdn.cn/ie_polyfill.js"></script><![endif]-->
<!--开发模式下不注入polyfill-->
<!--<script src="polyfill?_dist&amp;_inline"></script>-->
<link rel="stylesheet" href="https://cdn.cn/common.css">
<link rel="stylesheet" href="https://cdn.cn/login.css">
</head>
<body>
<script src="https://cdn.cn/common.js"></script>

<script src="https://cdn.cn/login.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist-js-prod/login.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist-js-prod/pagemap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"home":"https://cdn.cn/home.html","login":"https://cdn.cn/login.html","signup":"https://cdn.cn/signup.html"}
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist-js-prod/polyfill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist-js-prod/signup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: yellow;
}

20 changes: 20 additions & 0 deletions demo/auto-plugin-use-template/dist-js-prod/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<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">
<!--只在IE下注入ie_polyfill-->
<!--[if IE]><script src="https://cdn.cn/ie_polyfill.js"></script><![endif]-->
<!--开发模式下不注入polyfill-->
<!--<script src="polyfill?_dist&amp;_inline"></script>-->
<link rel="stylesheet" href="https://cdn.cn/common.css">
<link rel="stylesheet" href="https://cdn.cn/signup.css">
</head>
<body>
<script src="https://cdn.cn/common.js"></script>

<script src="https://cdn.cn/signup.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist-js-prod/signup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist/common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
color: red;
}

1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist/common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist/home.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: red;
}

13 changes: 13 additions & 0 deletions demo/auto-plugin-use-template/dist/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.cn/home.css">
</head>
<body>
<script src="https://cdn.cn/home.js"></script>


</body>
</html>
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist/home.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist/ie_polyfill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: blue;
}

13 changes: 13 additions & 0 deletions demo/auto-plugin-use-template/dist/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.cn/login.css">
</head>
<body>
<script src="https://cdn.cn/login.js"></script>


</body>
</html>
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist/login.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist/pagemap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"home":"https://cdn.cn/home.html","login":"https://cdn.cn/login.html","signup":"https://cdn.cn/signup.html"}
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist/polyfill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/dist/signup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: yellow;
}

13 changes: 13 additions & 0 deletions demo/auto-plugin-use-template/dist/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.cn/signup.css">
</head>
<body>
<script src="https://cdn.cn/signup.js"></script>


</body>
</html>
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/dist/signup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions demo/auto-plugin-use-template/src/home/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: red;
}
4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/src/home/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('./index.css');
require('../ignore');
require('../ignore/index.css');
alert('page home');
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/src/ie_polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alert('ie_polyfill');
3 changes: 3 additions & 0 deletions demo/auto-plugin-use-template/src/ignore/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: red;
}
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/src/ignore/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.error('this dir should be ingore by AutoWebPlugin');
3 changes: 3 additions & 0 deletions demo/auto-plugin-use-template/src/login/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: blue;
}
4 changes: 4 additions & 0 deletions demo/auto-plugin-use-template/src/login/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('./index.css');
require('../ignore');
require('../ignore/index.css');
alert('page login');
1 change: 1 addition & 0 deletions demo/auto-plugin-use-template/src/polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alert('polyfill');
3 changes: 3 additions & 0 deletions demo/auto-plugin-use-template/src/signup/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: yellow;
}
Loading