Skip to content

Commit

Permalink
Merge pull request #231 from cmux/0.13
Browse files Browse the repository at this point in the history
0.13.10
  • Loading branch information
Diablohu authored Mar 25, 2020
2 parents 3b913a3 + 81ca24c commit 0c5f859
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 22 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## [Unreleased]

## [0.13.10] - 2020-03-25

**koot**

- 错误修正
- 潜在的开发环境中的部分静态文件无法请求的问题
- SPA 项目在某些情况下静态资源打包路径错误的问题

## [0.13.9] - 2020-03-24

**koot**
Expand Down
2 changes: 1 addition & 1 deletion packages/koot-webpack/factory-config/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module.exports = async (kootConfig = {}) => {
// ====================================================================
if (ENV === 'prod' && STAGE === 'client' && TYPE === 'spa') {
process.env.WEBPACK_BUILD_STAGE = 'server';
if (!Array.isArray(config)) config = config[0];
if (!Array.isArray(config)) config = [config];
config = [
...config,
...(await transformConfigServer(kootBuildConfig))
Expand Down
18 changes: 9 additions & 9 deletions packages/koot-webpack/loaders/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = function(content) {
const {
length = defaultClassNameHashLength,
mode = 'replace',
readable = false,
prefixToRemove
readable = false
// prefixToRemove
} = loaderUtils.getOptions(this);

const keyword = 'component';
Expand Down Expand Up @@ -152,18 +152,18 @@ module.exports = function(content) {
// transformer(root);
postcssTransformDeclUrls(root, {
transformer: url => {
if (prefixToRemove)
result = result.replace(
new RegExp(`^${prefixToRemove}`),
''
);
// if (prefixToRemove)
// result = result.replace(
// new RegExp(`^${prefixToRemove}`),
// ''
// );
const resName = `__RES${importIndex}`;
importIndex++;
imports[resName] = url;
return `' + ${resName} + '`;
},
context: this.context
// prefixToRemove: this.prefixToRemove
context: this.context,
prefixToRemove: this.prefixToRemove
});

// 导出md5的class名字和处理后的css文本
Expand Down
6 changes: 5 additions & 1 deletion packages/koot-webpack/postcss/transform-decl-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const postcssTransformDeclUrls = (root, options = {}) => {
if (typeof root !== 'object') throw new Error('Missing parameter: `root`');
if (!root.toResult) throw new Error('Invalid parameter: `transformer`');

const { transformer, context } = options;
const {
transformer,
context
// prefixToRemove
} = options;

// 处理所有属性中的 `url()` 和 `image-set()` 的引用地址

Expand Down
8 changes: 8 additions & 0 deletions packages/koot/ReactApp/server/middlewares/router-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ const {
} = require('../../../defaults/webpack-dev-server');
const { dll, serviceWorker } = require('../../../defaults/dev-request-uri');

const getDevRoutes = require('../../../libs/get-dev-routes');

const { KOOT_DEV_DLL_FILE_CLIENT: fileDllClient } = process.env;

getDevRoutes().forEach(({ file, route }) => {
router.get(route, ctx => {
ctx.type = 'application/javascript';
ctx.body = fs.readFileSync(file);
});
});
router.get(dll, ctx => {
if (fileDllClient && fs.existsSync(fileDllClient)) {
ctx.type = 'application/javascript';
Expand Down
26 changes: 17 additions & 9 deletions packages/koot/ReactSPA/dev-server/extend.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
const fs = require('fs-extra')
const fs = require('fs-extra');

const { dll } = require('../../defaults/dev-request-uri')
const { dll } = require('../../defaults/dev-request-uri');
const getDevRoutes = require('../../libs/get-dev-routes');

/**
* 扩展 webpack-dev-server
* @param {Object} server
*/
module.exports = (app) => {
module.exports = app => {
getDevRoutes().forEach(({ file, route }) => {
app.get(`${route}`, function(req, res) {
res.type('application/javascript');
res.send(fs.readFileSync(file));
});
});
// console.log({files})
// console.log(server)
// return
const { KOOT_DEV_DLL_FILE_CLIENT: fileDll } = process.env
const { KOOT_DEV_DLL_FILE_CLIENT: fileDll } = process.env;
if (fileDll && fs.existsSync(fileDll))
app.get(`${dll}`, function (req, res) {
res.type('application/javascript')
res.send(fs.readFileSync(fileDll))
})
}
app.get(`${dll}`, function(req, res) {
res.type('application/javascript');
res.send(fs.readFileSync(fileDll));
});
};
33 changes: 33 additions & 0 deletions packages/koot/libs/get-dev-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path');
const glob = require('glob');

const getDirDevDll = require('./get-dir-dev-dll');

/**
* @typedef {Object} RouteMap
* @property {string} file - 硬盘路径
* @property {string} route - 访问路由/pathname
*/

/**
* _仅针对开发环境_ 获取静态文件路由,这些文件通常临时生成并保存在硬盘中
* @return {RouteMap[]}
*/
module.exports = () => {
if (process.env.WEBPACK_BUILD_ENV !== 'dev') return [];

const dirDevDll = getDirDevDll();

return glob
.sync(path.resolve(dirDevDll, '**/*'), {
dot: true
})
.map(file => {
let route = path.relative(dirDevDll, file);
if (route.substr(0, 1) !== '/') route = '/' + route;
return {
file,
route
};
});
};
3 changes: 2 additions & 1 deletion test/projects/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"scripts": {
"start": "koot-start",
"start:server": "koot-start --no-build",
"start:spa": "koot-start --type react-spa",
"build": "koot-build",
"build:client": "koot-build -c",
"build:server": "koot-build -s",
Expand Down Expand Up @@ -49,7 +50,7 @@
"private": true,
"sideEffects": false,
"koot": {
"version": "0.13.7"
"version": "0.13.9"
},
"devDependencies": {
"@types/inquirer": "^6.5.0",
Expand Down
2 changes: 1 addition & 1 deletion test/projects/standard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"private": true,
"sideEffects": false,
"koot": {
"version": "0.13.7"
"version": "0.13.9"
},
"devDependencies": {
"@types/inquirer": "^6.5.0",
Expand Down

0 comments on commit 0c5f859

Please sign in to comment.