From 03b4b164aa3f023beb8404baa5da1513533692a3 Mon Sep 17 00:00:00 2001 From: zhongzhi107 Date: Mon, 26 Mar 2018 14:21:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(config):=20=E5=A2=9E=E5=8A=A0=20`templateI?= =?UTF-8?q?njectPosition`=20=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8=E6=9D=A5?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E7=94=9F=E6=88=90=E7=BD=91=E9=A1=B5=E6=97=B6?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BE=80html=E4=B8=AD=E6=B3=A8=E5=85=A5=20as?= =?UTF-8?q?sets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ package.json | 2 +- src/config/packing.js | 15 +++++++-------- src/config/webpack.dll.babel.js | 2 +- src/config/webpack.serve.babel.js | 2 +- .../config/webpack.build.babel.js | 6 +++--- test/cases/html-template/test.serve.js | 9 +-------- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0efaaf6..24adaab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 的功能 + ## [2.6.6](https://github.com/packingjs/packing/compare/v2.6.5...v2.6.6) (2018-02-28) diff --git a/package.json b/package.json index 17308f3..c96256f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/config/packing.js b/src/config/packing.js index 07505e3..f869b21 100644 --- a/src/config/packing.js +++ b/src/config/packing.js @@ -63,9 +63,16 @@ export default { // 模版引擎类型,目前支持的类型有[html,pug,ejs,handlebars,smarty,velocity,artTemplate] templateEngine: 'html', + // 模版文件扩展名 templateExtension: '.html', + // 是否往模版中注入 assets [bool | string] + // false: 不注入 + // 'head': 在前注入 + // 'body': 在前注入 + templateInjectPosition: 'body', + // 本地访问的域名,为了调试方便,可能改成my.qunar.com localhost: 'localhost', @@ -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, diff --git a/src/config/webpack.dll.babel.js b/src/config/webpack.dll.babel.js index 4285234..6628b97 100644 --- a/src/config/webpack.dll.babel.js +++ b/src/config/webpack.dll.babel.js @@ -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 { diff --git a/src/config/webpack.serve.babel.js b/src/config/webpack.serve.babel.js index abf3063..5813f5e 100644 --- a/src/config/webpack.serve.babel.js +++ b/src/config/webpack.serve.babel.js @@ -18,7 +18,7 @@ const { port, hot, cssModules, - cssModulesIdentName = '[path][name]__[local]--[hash:base64:5]', + cssModulesIdentName, commonChunks, path: { src, diff --git a/test/cases/html-template-require/config/webpack.build.babel.js b/test/cases/html-template-require/config/webpack.build.babel.js index 85e9efe..5b0bace 100644 --- a/test/cases/html-template-require/config/webpack.build.babel.js +++ b/test/cases/html-template-require/config/webpack.build.babel.js @@ -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 = { @@ -19,5 +19,5 @@ export default (webpackConfig/* , program, appConfig */) => { // }; // } // }); - return webpackConfig; -}; + webpackConfig; + diff --git a/test/cases/html-template/test.serve.js b/test/cases/html-template/test.serve.js index 5cddd42..8be1e48 100644 --- a/test/cases/html-template/test.serve.js +++ b/test/cases/html-template/test.serve.js @@ -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'; @@ -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); });