From 4e8762e6f5cfeb1917f2cdb5c00764943abffab4 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Sat, 23 Apr 2022 12:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0wxml=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/loaders/wxml-loader.js | 13 ++++++++ config/webpack.config.js | 58 +++++++++++++++++++++++++++++------ lib/interface.d.ts | 8 ----- lib/template.js | 1 - package.json | 1 + plugins/WechatMpPlugin.js | 11 +++---- src/create.ts | 2 +- src/interface.ts | 9 ------ src/template.ts | 1 - 9 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 config/loaders/wxml-loader.js diff --git a/config/loaders/wxml-loader.js b/config/loaders/wxml-loader.js new file mode 100644 index 0000000..fcaba07 --- /dev/null +++ b/config/loaders/wxml-loader.js @@ -0,0 +1,13 @@ +const loaderUtils = require('loader-utils'); + +/** + * + * @param {*} content 文件信息 + * @param {*} map 文件映射信息 + * @param {*} meta 模块的元数据 + */ +module.exports = function (content, map, meta) { + // const options = loaderUtils.getOptions(this); + // console.log(content, options); + return content; +}; diff --git a/config/webpack.config.js b/config/webpack.config.js index 1595c14..42fdcfb 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -30,7 +30,7 @@ const relativeFileLoader = (ext = '[ext]') => { }; }; -const oakLoader = (ext = '[ext]') => { +const oakFileLoader = (ext = '[ext]') => { return { loader: 'file-loader', options: { @@ -38,7 +38,7 @@ const oakLoader = (ext = '[ext]') => { name: `[path][name].${ext}`, outputPath: (url, resourcePath, context) => { const outputPath = url.split( - 'oak-general-business/src/platforms/wechatMp/' + 'oak-general-business/wechatMp/' )[1]; return outputPath; }, @@ -66,12 +66,20 @@ module.exports = { '@': SOURCE, assert: require.resolve('assert'), }, - extensions: ['.ts', '.js', 'json'], + extensions: ['.ts', '.js'], symlinks: true, fallback: { crypto: require.resolve('crypto-browserify'), }, }, + resolveLoader: { + // 第一种使用别名的方式引入自定义的loader + alias: { + 'wxml-loader': path.resolve(__dirname, 'loaders/wxml-loader.js'), + }, + // 第二种方式选查找自己的loaders文件中有没有这个loader再查找node_modules文件 + // modules: [path.resolve(__dirname, 'loaders'), 'node_modules'], + }, module: { rules: [ { @@ -87,10 +95,16 @@ module.exports = { }, { test: /\.less$/, - include: /oak-general-business/, + include: /oak-general-business\/wechatMp/, + // include: [ + // path.resolve( + // process.cwd(), + // 'node_modules/oak-general-business/wechatMp' + // ), + // ], type: 'javascript/auto', use: [ - oakLoader('wxss'), + oakFileLoader('wxss'), { loader: 'less-loader', options: { @@ -118,6 +132,7 @@ module.exports = { // { // test: /\.json$/, // include: /src/, + // exclude: /node_modules/, // type: 'asset/resource', // generator: { // filename: `[path][name].[ext]`, @@ -128,11 +143,34 @@ module.exports = { { test: /\.(xml|wxml)$/, include: /src/, - type: 'asset/resource', - generator: { - filename: `[path][name].[ext]`, - }, - // use: [relativeFileLoader('wxml')], + // type: 'asset/resource', + // generator: { + // filename: `[path][name].[ext]`, + // }, + type: 'javascript/auto', + use: [ + relativeFileLoader('wxml'), + { + loader: 'wxml-loader', + }, + ], + }, + { + test: /\.(xml|wxml)$/, + include: /oak-general-business\/wechatMp/, + // include: [ + // path.resolve( + // process.cwd(), + // 'node_modules/oak-general-business/wechatMp' + // ), + // ], + type: 'javascript/auto', + use: [ + oakFileLoader('wxml'), + { + loader: 'wxml-loader', + }, + ], }, ], }, diff --git a/lib/interface.d.ts b/lib/interface.d.ts index eab36c0..a7367cf 100644 --- a/lib/interface.d.ts +++ b/lib/interface.d.ts @@ -46,11 +46,3 @@ export interface PackOptionsIgnore { type: string; value: string; } -/** - * @name oak-cli需要输入的参数 - * @export - * @interface OakInput - */ -export interface OakInput { - mode: string; -} diff --git a/lib/template.js b/lib/template.js index b006bf8..635e0fd 100644 --- a/lib/template.js +++ b/lib/template.js @@ -109,7 +109,6 @@ function tsConfigJsonContent() { }, "include": [ "./**/*.ts", - "scripts/webpack.js" ], "exclude": [ "node_modules" diff --git a/package.json b/package.json index fb38149..6caab31 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "fs-extra": "^10.0.0", "globby": "^11.1.0", "inquirer": "^7.3.3", + "loader-utils": "^3.2.0", "mini-css-extract-plugin": "^2.5.3", "postcss-less": "^6.0.0", "progress-bar-webpack-plugin": "^2.1.0", diff --git a/plugins/WechatMpPlugin.js b/plugins/WechatMpPlugin.js index aaf71c0..161f2ed 100644 --- a/plugins/WechatMpPlugin.js +++ b/plugins/WechatMpPlugin.js @@ -18,7 +18,6 @@ const requiredPath = require('required-path'); const pluginName = 'OakWeChatMpPlugin'; const OakPagePrefix = '@oak-general-business'; const OakPagePath = 'node_modules/oak-general-business/wechatMp/'; -// const oakPagePathRegExp = /node_modules\/oak-general-business\/src\/platforms\/wechatMp\//; function getIsOak(str) { return str.indexOf(OakPagePrefix) === 0; @@ -349,7 +348,7 @@ class OakWeChatMpPlugin { const entries = await globby(patterns, { cwd: this.basePath, nodir: true, - realpath: false, + realpath: true, ignore: [...extensions.map((ext) => `**/*${ext}`), ...exclude], dot: false, }); @@ -370,7 +369,7 @@ class OakWeChatMpPlugin { { cwd: process.cwd(), nodir: true, - realpath: false, + realpath: true, ignore: [...extensions.map((ext) => `**/*${ext}`), ...exclude], dot: false, } @@ -382,7 +381,7 @@ class OakWeChatMpPlugin { { cwd: process.cwd(), nodir: true, - realpath: false, + realpath: true, ignore: [...extensions.map((ext) => `**/*${ext}`), ...exclude], dot: false, } @@ -504,7 +503,7 @@ class OakWeChatMpPlugin { const emitAssets = []; for (let entry of this.assetsEntry) { const assets = path.resolve(this.basePath, entry); - if (/\.(sass|scss|css|less|styl)$/.test(assets)) { + if (/\.(sass|scss|css|less|styl|xml)$/.test(assets)) { continue; } const toTmit = async () => { @@ -539,7 +538,7 @@ class OakWeChatMpPlugin { } for (let entry of this.oakAssetsEntry) { const assets = path.resolve(process.cwd(), entry); - if (/\.(sass|scss|css|less|styl)$/.test(assets)) { + if (/\.(sass|scss|css|less|styl|xml)$/.test(assets)) { continue; } const toTmit = async () => { diff --git a/src/create.ts b/src/create.ts index 8b3c4aa..9a9ce67 100644 --- a/src/create.ts +++ b/src/create.ts @@ -19,7 +19,7 @@ import { projectConfigContentWithWeChatMp, oakConfigContentWithWeChatMp, } from './template'; -import { PromptInput, OakInput } from './interface'; +import { PromptInput } from './interface'; import { join } from 'path'; import inquirer from 'inquirer'; import axios from 'axios'; diff --git a/src/interface.ts b/src/interface.ts index 94339f4..0b88d5a 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -49,13 +49,4 @@ export interface PackOptions { export interface PackOptionsIgnore { type: string, value: string -} - -/** - * @name oak-cli需要输入的参数 - * @export - * @interface OakInput - */ -export interface OakInput { - mode: string, } \ No newline at end of file diff --git a/src/template.ts b/src/template.ts index e71a573..9d922fe 100644 --- a/src/template.ts +++ b/src/template.ts @@ -115,7 +115,6 @@ export function tsConfigJsonContent() { }, "include": [ "./**/*.ts", - "scripts/webpack.js" ], "exclude": [ "node_modules"