import npminstall from 'npminstall';
npminstall({
root: this.targetPath,
storeDir: this.storePath,
registry: getNpmRegistry(),
pkgs: [
{
name: this.packageName,
version: this.packageVersion
}
]
});阅读全文>>
一、前言
最近准备开发前端的一个模块化的库,业务级别,要求可以任意插拔随意组合。大型工程,需要多人维护。
以前的项目都是业务级,单个包项目。简单,便于管理。但是,当一个大的项目库代码量剧增之后,管理起来就是一件比较麻烦的事情,为了方便代码的共享,就需要将代码库拆分成独立的包。
调研了一下lerna库,适合我们的场景,babel即用这个工具进行管理。
二、lerna基础
初始化:
$ npm i -g lerna
$ mkdir lerna-repo && cd $_ $ lerna init
...阅读全文>>
const cac = require('cac');
const cli = cac.cac('lininn-theme');
cli.command('', '生成样式文件')
.option('-p, --platform <platform>', '配置平台')
.option('--prefix <prefix>', '配置前缀')
.option('--font <font>', '配置字体大小:normal|large|small,默认 normal')
.option...阅读全文>>
阅读全文>>
Step 1️:创建一个 Store Model
// ./src/stores/todo.ts
import { action, observable, computed } from 'mobx';
export interface ITodo {
id: number;
name: string;
desc: string;
done?: boolean;
}
let id = 0;
export class TodoStore {
@observable todos: ITodo[] = [];
// 利用计算属性计算完成个未完成个数
@compu...阅读全文>>
settings.json:
"eslint.options": {
"overrideConfig": {
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"no-debugger": "off"
}
}
},阅读全文>>
export default defineConfig({
cssLoader: {
modules: {
auto: true,
},
},
})阅读全文>>
window.location.replace
1
window.location.replace('要转向的页面') //不会有历史记录
1 2 3 4
let backLen = history.length history.forward() history.go(-backLen) // Return at the beginning window.location.replace('/#/home')
...阅读全文>>
原本打包过后是css-in-js,配置完MiniCssExtractPlugin后,可以将css单独打包出来
配置
1,安装npm install --save-dev mini-css-extract-plugin
2,将style-loader替换成MiniCssExtractPlugin.loader (style.loader,支持HMR,但MiniCssExtractPlugin目前正在支持(还没))
3,安装npm install --save-dev optimize-css-assets-webpack-...阅读全文>>
优先通过修改源代码来解决;修改后记得重启,有的依赖需重新处理
其次通过预构建或 CommonJS 插件处理;
为了解决这一问题,我对搜索到的数个 CommonJS 插件进行简单地试用,最终基于成熟、可靠、全面等几方面的考虑,采用 @rollup/plugin-commonjs 。
import commonjs from '@rollup/plugin-commonjs';
export default defineConfig({
plugins: [
commonjs...阅读全文>>