Skip to content

Commit

Permalink
feat: add env for language
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Mar 11, 2021
1 parent 62db6f7 commit c6d3dfd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/mini-vue.cjs.js

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

2 changes: 1 addition & 1 deletion lib/mini-vue.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/mini-vue.esm.js

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

2 changes: 1 addition & 1 deletion lib/mini-vue.esm.js.map

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import pkg from "./package.json";
import typescript from "rollup-plugin-typescript";
import sourceMaps from "rollup-plugin-sourcemaps";
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import replace from "@rollup/plugin-replace";

export default {
input: "./src/index.ts",
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('development'),
'process.env.VUE_ENV': JSON.stringify('browser')
"process.env.NODE_ENV": JSON.stringify("development"),
"process.env.VUE_ENV": JSON.stringify("browser"),
"process.env.LANGUAGE": JSON.stringify(process.env.LANGUAGE),
}),
resolve(),
commonjs(),
typescript({
exclude: "node_modules/**",
typescript: require("typescript")
typescript: require("typescript"),
}),
sourceMaps(),
],
output: [
{
format: "cjs",
file: pkg.main,
sourcemap: true
sourcemap: true,
},
{
name:"vue",
name: "vue",
format: "es",
file: pkg.module,
sourcemap: true
}
]
sourcemap: true,
},
],
};
6 changes: 4 additions & 2 deletions src/mini-core/LanguageTranslator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// LANGUAGE=cn yarn build
// LANGUAGE 环境变量可以控制打包的语言

// TODO 需要后面扩展 map 即可
const c2eMap = {
你好: "hello",
Expand All @@ -11,8 +14,7 @@ const e2cMap = {
export default class LanguageTranslator {
private currentLanguage: string;
constructor() {
// TODO这个值可以基于环境变量自行控制
this.currentLanguage = "cn";
this.currentLanguage = process.env.LANGUAGE || "cn";
// this.currentLanguage = "en";
}

Expand Down

0 comments on commit c6d3dfd

Please sign in to comment.