-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
989d659
commit 266473d
Showing
16 changed files
with
282 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"dependencies": { | ||
"a": "^8.13" | ||
}, | ||
"devDependencies": { | ||
"b": "^1.3.2", | ||
"c": "^1.18.2" | ||
} | ||
} | ||
"dependencies": { | ||
"a": "^8.13" | ||
}, | ||
"devDependencies": { | ||
"b": "^1.3.2", | ||
"c": "^1.18.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
extends: [ | ||
'eslint-config-qunar-typescript-base' | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
useBuiltIns: 'usage', | ||
targets: { | ||
browsers: [ | ||
'> 1%', | ||
'Android >= 4.4', | ||
'IOS >= 7', | ||
'ie >= 10' | ||
] | ||
} | ||
} | ||
], | ||
'@babel/typescript' | ||
], | ||
plugins: [ | ||
[ | ||
'@babel/plugin-transform-runtime', | ||
{ | ||
helpers: false, | ||
regenerator: true | ||
} | ||
], | ||
'add-module-exports', | ||
[ | ||
'@babel/plugin-proposal-decorators', | ||
{ | ||
legacy: true | ||
} | ||
], | ||
'@babel/plugin-syntax-dynamic-import', | ||
'@babel/plugin-syntax-import-meta', | ||
'@babel/plugin-proposal-class-properties', | ||
'@babel/plugin-proposal-json-strings', | ||
'@babel/plugin-proposal-function-sent', | ||
'@babel/plugin-proposal-export-namespace-from', | ||
'@babel/plugin-proposal-numeric-separator', | ||
'@babel/plugin-proposal-throw-expressions', | ||
'@babel/plugin-proposal-export-default-from', | ||
'@babel/plugin-proposal-logical-assignment-operators', | ||
'@babel/plugin-proposal-optional-chaining', | ||
[ | ||
'@babel/plugin-proposal-pipeline-operator', | ||
{ | ||
proposal: 'minimal' | ||
} | ||
], | ||
'@babel/plugin-proposal-nullish-coalescing-operator', | ||
'@babel/plugin-proposal-do-expressions', | ||
'@babel/plugin-proposal-function-bind' | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* 这个文件可以修改build的默认设置 | ||
* 默认配置请看 `node_modules/packing/config/webpack.build.babel.js` | ||
* | ||
* @param object webpackConfig 默认配置对象 | ||
* @param object program packing-cli程序对象 | ||
* @param object appConfig config/packing.js中的配置 | ||
*/ | ||
|
||
export default (webpackConfig/* , program, appConfig */) => { | ||
const config = webpackConfig; | ||
|
||
// babel-loader 中增加对 .ts 的匹配 | ||
const [jsloader] = config.module.rules; | ||
jsloader.test = /\.(t|j)sx?$/i; | ||
|
||
// 设置文件扩展名,支持 .ts | ||
config.resolve.extensions = ['.js', '.ts']; | ||
|
||
// webpackConfig 为系统默认的webpack配置,此处可以根据项目情况修改 | ||
// 修改 entry | ||
// config.entry = 'xxx/xxx.js'; | ||
// 修改 plugins(修改 = 先删除现有的,再添加新的) | ||
// config.plugins = config.plugins.filter(plugin => !(plugin.filename && plugin.id)); | ||
// config.plugins.push( | ||
// new ExtractTextPlugin({ | ||
// filename: '[name]-[contenthash:8].css', | ||
// allChunks: true | ||
// }) | ||
// ) | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* 这个文件可以修改serve的默认设置 | ||
* 默认配置请看 `node_modules/packing/config/webpack.serve.babel.js` | ||
* | ||
* @param object webpackConfig 默认配置对象 | ||
* @param object program packing-cli程序对象 | ||
* @param object appConfig config/packing.js中的配置 | ||
*/ | ||
|
||
export default (webpackConfig/* , program, appConfig */) => { | ||
const config = webpackConfig; | ||
|
||
// babel-loader 中增加对 .ts 的匹配 | ||
const [jsloader] = config.module.rules; | ||
jsloader.test = /\.(t|j)sx?$/i; | ||
|
||
// 设置文件扩展名,支持 .ts | ||
config.resolve.extensions = ['.js', '.ts']; | ||
|
||
// webpackConfig 为系统默认的webpack配置,此处可以根据项目情况修改 | ||
// 修改 entry | ||
// config.entry = 'xxx/xxx.js'; | ||
// 修改 plugins(修改 = 先删除现有的,再添加新的) | ||
// config.plugins = config.plugins.filter(plugin => !(plugin.filename && plugin.id)); | ||
// config.plugins.push( | ||
// new ExtractTextPlugin({ | ||
// filename: '[name]-[contenthash:8].css', | ||
// allChunks: true | ||
// }) | ||
// ) | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
process.env.CONTEXT = __dirname; | ||
|
||
const { getTestCaseName } = require('../../util'); | ||
|
||
describe(getTestCaseName(), async () => { | ||
require('./test'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"@babel/preset-typescript": "^7.6.0", | ||
"eslint-config-qunar-typescript-base": "1.0.2", | ||
"typescript": "^3.6.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const a: string = 'a'; | ||
|
||
export default a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import a from './a'; | ||
|
||
console.log(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
title: '首页', | ||
// 以下变量供自定义模版变量替换使用,自定义模版变量格式为 __var__ | ||
name: 'Packing', | ||
me: '🐶' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
doctype html | ||
html | ||
head | ||
block meta | ||
meta(http-equiv="Content-Type" content="text/html;charset=utf-8") | ||
meta(content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport") | ||
meta(name="apple-mobile-web-app-capable" content="yes") | ||
meta(name="apple-mobile-web-app-status-bar-style" content="black") | ||
meta(content="telephone=no" name="format-detection") | ||
block title | ||
title Default title | ||
block style | ||
body | ||
block content | ||
block script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extends /layout/default.pug | ||
|
||
block content | ||
h1 Hello, #{name} | ||
h2 #{me} | ||
ul | ||
li | ||
a(href="/") Home | ||
li | ||
a(href="/about") About |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { resolve } from 'path'; | ||
import request from 'supertest'; | ||
import webpack from 'webpack'; | ||
import Express from 'express'; | ||
import webpackDevMiddleware from 'webpack-dev-middleware'; | ||
import urlrewrite from 'packing-urlrewrite'; | ||
import '../../../src'; | ||
import { pRequire, middleware, getContext } from '../../../src'; | ||
|
||
describe(getTestCaseName(), async () => { | ||
let app; | ||
before(() => { | ||
const context = getContext(); | ||
const appConfig = pRequire('config/packing'); | ||
const webpackConfig = pRequire('config/webpack.serve.babel', {}, appConfig); | ||
|
||
const mwOptions = process.env.DEBUG ? { | ||
serverSideRender: true | ||
} : { | ||
serverSideRender: true, | ||
// 禁止 webpack-dev-middleware 输出日志 | ||
logger: { | ||
info: () => {}, | ||
error: console.log | ||
} | ||
}; | ||
|
||
app = new Express(); | ||
app.use(Express.static(resolve(context, appConfig.path.tmpDll))); | ||
const compiler = webpack(webpackConfig); | ||
const webpackDevMiddlewareInstance = webpackDevMiddleware(compiler, mwOptions); | ||
webpackDevMiddlewareInstance.waitUntilValid(async () => { | ||
app.use(urlrewrite(appConfig.rewriteRules)); | ||
middleware(app, appConfig); | ||
}); | ||
app.use(webpackDevMiddlewareInstance); | ||
}); | ||
|
||
describe('/', async () => { | ||
let res; | ||
before(async () => { | ||
res = await request(app.listen()).get('/index'); | ||
console.log(res.text); | ||
}); | ||
|
||
it('应该正常返回网页', async () => { | ||
res.status.should.eql(200); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"target": "es5", | ||
"sourceMap": true, | ||
"outDir": "./dist", | ||
"baseUrl": "./src", | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"lib": [ | ||
"es2017", | ||
"dom" | ||
] | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters