Skip to content

Commit

Permalink
Merge branch 'main' into optimize/code
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Apr 10, 2024
2 parents 7191b32 + 49a7fe0 commit a7fc47d
Show file tree
Hide file tree
Showing 50 changed files with 249 additions and 90 deletions.
5 changes: 0 additions & 5 deletions .changeset/polite-nails-remember.md

This file was deleted.

4 changes: 2 additions & 2 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions crates/compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.5](https://github.com/farm-fe/farm/compare/farmfe_compiler-v0.0.4...farmfe_compiler-v0.0.5) - 2024-04-09

### Other
- updated the following local packages: farmfe_plugin_static_assets

## [0.0.4](https://github.com/farm-fe/farm/compare/farmfe_compiler-v0.0.3...farmfe_compiler-v0.0.4) - 2024-04-08

### Added
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "farmfe_compiler"
version = "0.0.4"
version = "0.0.5"
edition = "2021"
authors = ["brightwu(吴明亮) <1521488775@qq.com>"]
license = "MIT"
Expand All @@ -19,7 +19,7 @@ farmfe_plugin_html = { path = "../plugin_html", version = "0.0.4" }
farmfe_plugin_tree_shake = { path = "../plugin_tree_shake", version = "0.0.4" }
farmfe_plugin_css = { path = "../plugin_css", version = "0.0.5" }
farmfe_plugin_lazy_compilation = { path = "../plugin_lazy_compilation", version = "0.0.4" }
farmfe_plugin_static_assets = { path = "../plugin_static_assets", version = "0.0.4" }
farmfe_plugin_static_assets = { path = "../plugin_static_assets", version = "0.0.5" }
farmfe_plugin_minify = { path = "../plugin_minify", version = "0.0.4" }
farmfe_toolkit = { path = "../toolkit", version = "0.0.6" }
farmfe_utils = { path = "../utils", version = "0.1.4" }
Expand Down
5 changes: 5 additions & 0 deletions crates/plugin_static_assets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.5](https://github.com/farm-fe/farm/compare/farmfe_plugin_static_assets-v0.0.4...farmfe_plugin_static_assets-v0.0.5) - 2024-04-09

### Fixed
- static assets transform and sass import watch ([#1145](https://github.com/farm-fe/farm/pull/1145))

## [0.0.4](https://github.com/farm-fe/farm/compare/farmfe_plugin_static_assets-v0.0.3...farmfe_plugin_static_assets-v0.0.4) - 2024-04-08

### Other
Expand Down
2 changes: 1 addition & 1 deletion crates/plugin_static_assets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "farmfe_plugin_static_assets"
version = "0.0.4"
version = "0.0.5"
edition = "2021"
authors = ["brightwu(吴明亮) <1521488775@qq.com>"]
license = "MIT"
Expand Down
5 changes: 0 additions & 5 deletions crates/plugin_static_assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ impl Plugin for FarmPluginStaticAssets {
) -> farmfe_core::error::Result<Option<farmfe_core::plugin::PluginLoadHookResult>> {
let path = Path::new(param.resolved_path);
let extension = path.extension().and_then(|s| s.to_str());
let is_query_valid = param.query.is_empty() || is_asset_query(&param.query);
// ignore invalid query
if !is_query_valid {
return Ok(None);
}

if let Some(source) = param.resolved_path.strip_prefix(PUBLIC_ASSET_PREFIX) {
return Ok(Some(farmfe_core::plugin::PluginLoadHookResult {
Expand Down
24 changes: 11 additions & 13 deletions examples/public-dir/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="root"></div>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="root"></div>



<script src="./newPublic/test.js"></script>
<script src="./src/index.tsx"></script>
</body>
<script src="./newPublic/test.js"></script>
<script src="./src/index.tsx"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion examples/public-dir/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "public-dir",
"name": "@farmfe-examples/public-dir",
"version": "1.0.0",
"private": true,
"dependencies": {
"clsx": "^1.2.1",
"react": "18",
Expand Down
2 changes: 1 addition & 1 deletion examples/sass/src/style/dep.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
color: red;
width: 200px;
height: 50px;
}
}
5 changes: 5 additions & 0 deletions examples/static-assets/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"root": true,
"extends": "../../.eslintrc.base.json",
"rules": {}
}
2 changes: 2 additions & 0 deletions examples/static-assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
build
10 changes: 10 additions & 0 deletions examples/static-assets/farm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from '@farmfe/core';
import sass from '@farmfe/js-plugin-sass';

export default defineConfig({
plugins: [
sass({
legacy: true
})
]
})
12 changes: 12 additions & 0 deletions examples/static-assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script src="./src/index.ts"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions examples/static-assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@farmfe-examples/static-assets",
"version": "0.0.1",
"private": true,
"type": "module",
"devDependencies": {
"@farmfe/cli": "workspace:*",
"@farmfe/core": "workspace:*",
"@farmfe/js-plugin-sass": "workspace:*"
},
"scripts": {
"start": "farm start",
"build": "farm build",
"preview": "farm preview"
}
}
3 changes: 3 additions & 0 deletions examples/static-assets/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './style/index.scss';

document.body.innerHTML = '<div id="root"><div>Hello World</div></div>';
14 changes: 14 additions & 0 deletions examples/static-assets/src/style/dep/font.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@font-face {
font-family: 'iconfont'; /* Project id 2208059 */
src: url('iconfont.woff2?t=1671895108120') format('woff2'),
url('iconfont.woff?t=1671895108120') format('woff'),
url('iconfont.ttf?t=1671895108120') format('truetype');
}

body {
font-family: 'iconfont';
}

body:before {
content: '\e620';
}
Binary file added examples/static-assets/src/style/dep/iconfont.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions examples/static-assets/src/style/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './dep/font.scss';
10 changes: 10 additions & 0 deletions js-plugins/sass/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @farmfe/js-plugin-sass

## 2.5.4

### Patch Changes

- e1071eca: fix sass files watch and static assets transform
- Updated dependencies [e1071eca]
- Updated dependencies [6cbc9fa8]
- Updated dependencies [2ada5819]
- @farmfe/core@1.0.16

## 2.5.3

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions js-plugins/sass/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@farmfe/js-plugin-sass",
"version": "2.5.3",
"version": "2.5.4",
"description": "support scss compile for farm.",
"main": "./build/cjs/index.cjs",
"types": "./build/cjs/index.d.ts",
Expand Down Expand Up @@ -46,13 +46,13 @@
"license": "MIT",
"devDependencies": {
"@farmfe/cli": "workspace:*",
"@farmfe/core": "workspace:^1.0.11",
"@farmfe/core": "workspace:^1.0.16",
"@farmfe/js-plugin-dts": "workspace:*",
"sass": "^1.62.1",
"sass-embedded": "^1.62.0"
},
"peerDependencies": {
"@farmfe/core": "workspace:^1.0.11",
"@farmfe/core": "workspace:^1.0.16",
"sass": "^1.3.0",
"sass-embedded": "*"
}
Expand Down
45 changes: 29 additions & 16 deletions js-plugins/sass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ async function resolveDependency(
ctx
);
if (result) return result;
} catch (_error) {}
} catch (_error) {
/* do nothing */
}
}

if (default_import_error) {
Expand Down Expand Up @@ -259,24 +261,29 @@ async function compileScss(param: CompileCssParams) {
root
} = param;

const { css, sourceMap } = (await sassImpl.compileStringAsync(
const { css, sourceMap, loadedUrls } = (await sassImpl.compileStringAsync(
`${additionContext}\n${transformParam.content}`,
{
...(options?.sassOptions ?? {}),
sourceMap: options.sassOptions?.sourceMap ?? sourceMapEnabled,
url: pathToFileURL(transformParam.resolvedPath),
importers: [
{
canonicalize(url, _) {
async canonicalize(url, _) {
// file:///xxxx
// /xxx
// ./xxx
return pathToFileURL(normalizePath(url, root));
const normalizedPath = normalizePath(url, root);
const normalizedUrl = path.relative(root, normalizedPath);
const filePath = await resolveDependency(
normalizedUrl,
transformParam,
ctx
);
return pathToFileURL(filePath);
},
async load(canonicalUrl) {
const file = fileURLToPath(canonicalUrl);
const url = path.relative(root, file);
const filePath = await resolveDependency(url, transformParam, ctx);
const filePath = fileURLToPath(canonicalUrl);
const { contents } = await rebaseUrls(
filePath,
transformParam.resolvedPath,
Expand All @@ -302,6 +309,14 @@ async function compileScss(param: CompileCssParams) {
} as StringOptions<'async'>
)) as CompileResult;

for (const fileUrl of loadedUrls) {
const file = fileURLToPath(fileUrl);

if (file === transformParam.resolvedPath) continue;

ctx.addWatchFile(transformParam.resolvedPath, file);
}

return { css, sourceMap };
}

Expand All @@ -323,15 +338,8 @@ async function compileScssLegacy(param: CompileCssParams) {
sourceMap: options.sassOptions?.sourceMap ?? sourceMapEnabled,
outFile: transformParam.resolvedPath,
importer: [
function (url, importer, done) {
resolveDependency(
url,
{
...transformParam,
moduleId: importer
},
ctx
).then((resolvedPath) => {
function (url, _, done) {
resolveDependency(url, transformParam, ctx).then((resolvedPath) => {
rebaseUrls(
resolvedPath,
transformParam.resolvedPath,
Expand Down Expand Up @@ -359,6 +367,11 @@ async function compileScssLegacy(param: CompileCssParams) {
return;
}

result.stats.includedFiles.forEach((file) => {
if (file === transformParam.resolvedPath) return;
ctx.addWatchFile(transformParam.resolvedPath, file);
});

resolve({ css: result.css.toString(), sourceMap: result.map });
}
);
Expand Down
2 changes: 1 addition & 1 deletion js-plugins/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"solid-js": "^1.7.8"
},
"peerDependencies": {
"@farmfe/core": "workspace:^1.0.15"
"@farmfe/core": "workspace:^1.0.16"
},
"files": [
"build"
Expand Down
2 changes: 1 addition & 1 deletion js-plugins/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"source-map": "^0.7.4"
},
"peerDependencies": {
"@farmfe/core": "workspace:^1.0.15",
"@farmfe/core": "workspace:^1.0.16",
"less": "*",
"sass": "*",
"stylus": "*"
Expand Down
8 changes: 8 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @farmfe/core

## 1.0.16

### Patch Changes

- e1071eca: fix sass files watch and static assets transform
- 6cbc9fa8: resolve config file with set NODE_ENV
- 2ada5819: Add parsing in alias to node_modules

## 1.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@farmfe/core",
"version": "1.0.15",
"version": "1.0.16",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ async function readConfigFile(
progress: false
}
},
logger
logger,
inlineOptions.mode as CompilationMode
);

const compiler = new Compiler({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function build(
): Promise<void> {
const logger = inlineConfig.logger ?? new Logger();
setProcessEnv('production');

const resolvedUserConfig = await resolveConfig(
inlineConfig,
logger,
Expand Down

0 comments on commit a7fc47d

Please sign in to comment.