Skip to content

Commit

Permalink
feat(config): 增加 templateInjectPosition 参数,用来控制生成网页时是否往html中注入 assets
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongzhi107 committed Mar 26, 2018
1 parent c1e991b commit 03b4b16
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ All notable changes to this project will be documented in this file. See [standa
}
```

- 设置 `packing/config/packing.js` 中的 `templateInjectPosition: false` 来关闭生成网页文件时自动注入 assets 的功能

<a name="2.6.6"></a>
## [2.6.6](https://github.com/packingjs/packing/compare/v2.6.5...v2.6.6) (2018-02-28)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"license": "MIT",
"scripts": {
"build": "rimraf dist && babel src -d dist",
"lint": "eslint --fix --quiet \"src/**/*.js\"",
"lint": "eslint --fix --quiet \"src/**/*.js\" \"test/**/*.js\"",
"postrelease": "git push && git push origin --tags",
"prepare": "npm run build",
"release": "standard-version && npm publish",
Expand Down
15 changes: 7 additions & 8 deletions src/config/packing.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ export default {

// 模版引擎类型,目前支持的类型有[html,pug,ejs,handlebars,smarty,velocity,artTemplate]
templateEngine: 'html',

// 模版文件扩展名
templateExtension: '.html',

// 是否往模版中注入 assets [bool | string]
// false: 不注入
// 'head': 在</head>前注入
// 'body': 在</body>前注入
templateInjectPosition: 'body',

// 本地访问的域名,为了调试方便,可能改成my.qunar.com
localhost: 'localhost',

Expand Down Expand Up @@ -141,14 +148,6 @@ export default {
// '^/hello': 'http://localhost:3001/123/4.html',
},

// 用于在build中打开模板注释的配置
// 可选值
// String: 'html', 'js', 'css';预置对3种代码处理。
// RegExp: 使用正则来替换注释代码。
// Function: 接受一个字符串参数,该参数为文件内容,返回处理后的字符串。
// 参考:https://github.com/LHoin/webpack-uncomment-block
// uncommentPattern: 'html',

// 是否使用GraphQL-mock-server
graphqlMockServer: false,

Expand Down
2 changes: 1 addition & 1 deletion src/config/webpack.dll.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import pRequire from '../util/require';
*/

export default () => {
const { CONTEXT, NODE_ENV } = process.env;
const { CONTEXT } = process.env;
const context = CONTEXT || process.cwd();

const {
Expand Down
2 changes: 1 addition & 1 deletion src/config/webpack.serve.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
port,
hot,
cssModules,
cssModulesIdentName = '[path][name]__[local]--[hash:base64:5]',
cssModulesIdentName,
commonChunks,
path: {
src,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// import path from 'path';

export default (webpackConfig/* , program, appConfig */) => {
export default webpackConfig =>
// webpackConfig.plugins.forEach((plugin) => {
// if (plugin.constructor.name === 'PackingTemplatePlugin') {
// plugin.options = {
Expand All @@ -19,5 +19,5 @@ export default (webpackConfig/* , program, appConfig */) => {
// };
// }
// });
return webpackConfig;
};
webpackConfig;

9 changes: 1 addition & 8 deletions test/cases/html-template/test.serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import request from 'supertest';
import webpack from 'webpack';
import Express from 'express';
import webpackDevMiddleware from 'webpack-dev-middleware';
import urlrewrite from 'packing-urlrewrite';
import { middleware } from 'packing-template';
import '../../../src/util/babel-register';
import pRequire from '../../../src/util/require';
Expand All @@ -27,13 +26,7 @@ describe('serve', async () => {
const compiler = webpack(webpackConfig);
const webpackDevMiddlewareInstance = webpackDevMiddleware(compiler, mwOptions);
webpackDevMiddlewareInstance.waitUntilValid(async () => {
middleware(app, appConfig, {
// template: path.resolve(__dirname, 'template.html') // ,
// inject: 'head',
// favicon: 'xxx.png'
// charset: 'gb2312'
});
// app.use(urlrewrite(appConfig.rewriteRules));
middleware(app, appConfig);
});
app.use(webpackDevMiddlewareInstance);
});
Expand Down

0 comments on commit 03b4b16

Please sign in to comment.