Skip to content

Commit

Permalink
feat: dev mode WXML compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
LastLeaf committed Jul 23, 2024
1 parent 52c3319 commit adebace
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions glass-easel-miniprogram-template/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ module.exports = [
resourceFilePattern: /\.(jpg|jpeg|png|gif|html)$/,
// the default entry
defaultEntry: 'pages/index/index',
// compile with more debug information (unset to follow the webpack mode)
// dev: false,
}),
],
},
Expand Down
1 change: 1 addition & 0 deletions glass-easel-miniprogram-webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ plugins: [

| Options | Explanation |
| ------- | ----------- |
| dev | compile with more debug information (default to `false` if the webpack is in `production` mode) |
| path | the mini-program-like directory to be compiled (default to `src` ) |
| resourceFilePattern | the filename pattern (in the mini-program-like directory) to be copied into the webpack output path |
| defaultEntry | the mini-program page to be loaded on startup |
Expand Down
9 changes: 8 additions & 1 deletion glass-easel-miniprogram-webpack-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const CACHE_ETAG = 1
const HOST_STYLES_MODULE = '__glass_easel_host_styles__.wxss'

type PluginConfig = {
dev?: boolean
path: string
resourceFilePattern: RegExp
defaultEntry: string
Expand Down Expand Up @@ -176,6 +177,7 @@ class StyleSheetManager {
}

export class GlassEaselMiniprogramWebpackPlugin implements WebpackPluginInstance {
dev?: boolean
path: string
resourceFilePattern: RegExp
defaultEntry: string
Expand All @@ -185,6 +187,7 @@ export class GlassEaselMiniprogramWebpackPlugin implements WebpackPluginInstance
virtualModules = new VirtualModulesPlugin() as VirtualModulePluginType

constructor(options: Partial<PluginConfig>) {
this.dev = options.dev
this.path = options.path || './src'
this.resourceFilePattern = options.resourceFilePattern || /\.(jpg|jpeg|png|gif)$/
this.defaultEntry = options.defaultEntry || 'pages/index/index'
Expand All @@ -193,6 +196,10 @@ export class GlassEaselMiniprogramWebpackPlugin implements WebpackPluginInstance
}

apply(compiler: Compiler) {
const devMode =
this.dev === undefined
? compiler.options.mode === 'development' || compiler.options.mode === 'none'
: !!this.dev
const codeRoot = path.resolve(this.path)
const compInfoMap = Object.create(null) as {
[compPath: string]: { main: string; taskConfig: unknown; hasWxss: boolean }
Expand Down Expand Up @@ -470,7 +477,7 @@ export class GlassEaselMiniprogramWebpackPlugin implements WebpackPluginInstance
compilation.hooks.finishModules.tapPromise(PLUGIN_NAME, async (modules) => {
const tasks: Promise<any>[] = []
let indexModule: NormalModule | undefined
const tmplGroup = new TmplGroup()
const tmplGroup = devMode ? TmplGroup.newDev() : new TmplGroup()

// collect compilation results
// eslint-disable-next-line no-restricted-syntax
Expand Down
8 changes: 4 additions & 4 deletions glass-easel-template-compiler/src/proc_gen/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ impl Element {
w.function_args("N,C", |w| {
if group.dev() {
w.expr_stmt(|w| {
write!(w, "N._$wxTmplDevArgs=[")?;
write!(w, "N._$wxTmplDevArgs={{A:[")?;
self.collect_active_attribute_names(|str| {
write!(w, "{},", str)
})?;
write!(w, "]")?;
write!(w, "]}}")?;
Ok(())
})?;
}
Expand Down Expand Up @@ -1068,11 +1068,11 @@ impl Element {
w.function_args("N", |w| {
if group.dev() {
w.expr_stmt(|w| {
write!(w, "N._$wxTmplDevArgs=[")?;
write!(w, "N._$wxTmplDevArgs={{A:[")?;
self.collect_active_attribute_names(|str| {
write!(w, "{},", str)
})?;
write!(w, "]")?;
write!(w, "]}}")?;
Ok(())
})?;
}
Expand Down

0 comments on commit adebace

Please sign in to comment.