-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #877 from umijs/dev-for-raw
feat: Dev for raw
- Loading branch information
Showing
8 changed files
with
58 additions
and
0 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
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,28 @@ | ||
use std::sync::Arc; | ||
|
||
use mako_core::anyhow::Result; | ||
|
||
use crate::compiler::Context; | ||
use crate::load::{read_content, Content}; | ||
use crate::plugin::{Plugin, PluginLoadParam}; | ||
|
||
pub struct RawPlugin {} | ||
|
||
impl Plugin for RawPlugin { | ||
fn name(&self) -> &str { | ||
"raw" | ||
} | ||
|
||
fn load(&self, param: &PluginLoadParam, _context: &Arc<Context>) -> Result<Option<Content>> { | ||
if param.task.request.query.iter().any(|item| item.0 == "raw") { | ||
let file_content = read_content(param.task.request.path.as_str())?; | ||
let json_string = serde_json::to_string(&file_content)?; | ||
|
||
return Ok(Some(Content::Js(format!( | ||
"module.exports = {}", | ||
json_string | ||
)))); | ||
} | ||
Ok(None) | ||
} | ||
} |
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,17 @@ | ||
const assert = require("assert"); | ||
const { parseBuildResult } = require("../../../scripts/test-utils"); | ||
const { files } = parseBuildResult(__dirname); | ||
|
||
const content = files["index.js"]; | ||
|
||
assert( | ||
content.includes( | ||
'module.exports = "const Hello = \\"Hello\\";\\nconst World = `World`;\\n"' | ||
), | ||
"support convert js" | ||
); | ||
|
||
assert( | ||
content.includes("h1 {\\n background-size: 20px 20px;\\n}\\n"), | ||
"support convert css" | ||
); |
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 @@ | ||
{} |
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 @@ | ||
h1 { | ||
background-size: 20px 20px; | ||
} |
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,2 @@ | ||
const Hello = "Hello"; | ||
const World = `World`; |
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 @@ | ||
import css from "./foo.css?raw"; | ||
console.log(css); | ||
|
||
import js from "./foo.ts?raw"; | ||
console.log(js); |