windy
5 years ago
44 changed files with 5087 additions and 522 deletions
@ -0,0 +1,34 @@
|
||||
module.exports = function (api) { |
||||
api.cache(true); |
||||
const presets = [ |
||||
[ |
||||
"@babel/preset-env", |
||||
{ |
||||
targets: { |
||||
ie: 8, |
||||
}, |
||||
}, |
||||
], |
||||
"@babel/preset-typescript", |
||||
]; |
||||
const plugins = [ |
||||
[ |
||||
"@babel/plugin-proposal-decorators", |
||||
{ |
||||
legacy: true, |
||||
}, |
||||
], |
||||
"@babel/plugin-proposal-class-properties", |
||||
"@babel/plugin-transform-block-scoping", |
||||
["@babel/plugin-transform-classes", { |
||||
loose: true, |
||||
}], |
||||
"@babel/plugin-transform-proto-to-assign", |
||||
"@babel/plugin-transform-modules-commonjs", |
||||
]; |
||||
|
||||
return { |
||||
presets, |
||||
plugins, |
||||
}; |
||||
}; |
@ -0,0 +1,34 @@
|
||||
module.exports = function (api) { |
||||
api.cache(true); |
||||
const presets = [ |
||||
[ |
||||
"@babel/preset-env", |
||||
{ |
||||
targets: { |
||||
ie: 9, |
||||
chrome: 47, |
||||
}, |
||||
}, |
||||
], |
||||
"@babel/preset-typescript", |
||||
]; |
||||
const plugins = [ |
||||
[ |
||||
"@babel/plugin-proposal-decorators", |
||||
{ |
||||
legacy: true, |
||||
}, |
||||
], |
||||
"@babel/plugin-proposal-class-properties", |
||||
"@babel/plugin-transform-block-scoping", |
||||
["@babel/plugin-transform-classes", { |
||||
loose: true, |
||||
}], |
||||
"@babel/plugin-transform-proto-to-assign", |
||||
]; |
||||
|
||||
return { |
||||
presets, |
||||
plugins, |
||||
}; |
||||
}; |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,39 @@
|
||||
const Concat = require("concat-with-sourcemaps"); |
||||
const { resolve } = require("path"); |
||||
const fs = require("fs"); |
||||
|
||||
function unionJs(filenames) { |
||||
const filename = filenames[0]; |
||||
|
||||
var concat = new Concat(true, filename, "\n"); |
||||
|
||||
filenames.forEach(filename => { |
||||
concat.add( |
||||
filename, |
||||
fs.readFileSync(resolve(__dirname, `../../dist/${filename}`)), |
||||
fs.readFileSync(resolve(__dirname, `../../dist/${filename}.map`)).toString() |
||||
); |
||||
}); |
||||
|
||||
const filenameParts = filename.split("/"); |
||||
|
||||
concat.add(null, `//# sourceMappingURL=${filenameParts[filenameParts.length - 1]}.map`); |
||||
|
||||
var concatenatedContent = concat.content; |
||||
var sourceMapForContent = concat.sourceMap; |
||||
|
||||
fs.writeFileSync(resolve(__dirname, "../../dist", filename), concatenatedContent, { |
||||
encoding: "utf8", |
||||
}); |
||||
|
||||
fs.writeFileSync(resolve(__dirname, "../../dist", `${filename}.map`), sourceMapForContent, { |
||||
encoding: "utf8", |
||||
}); |
||||
} |
||||
|
||||
unionJs(["bundle.min.js", "es5.fineui.js"]); |
||||
unionJs(["bundle.ie.min.js", "ie.fineui.js"]); |
||||
unionJs(["fineui.min.js", "es5.fineui.js"]); |
||||
unionJs(["fineui.ie.min.js", "ie.fineui.js"]); |
||||
unionJs(["2.0/fineui.min.js", "es5.fineui.js"]); |
||||
unionJs(["2.0/fineui.ie.min.js", "ie.fineui.js"]); |
@ -0,0 +1,13 @@
|
||||
interface Obj { |
||||
[key: string]: any; |
||||
} |
||||
|
||||
declare let BI: Obj & import("../typescript/index")._BI; |
||||
|
||||
// declare let BI: Obj;
|
||||
|
||||
declare const Fix: Obj; |
||||
|
||||
declare interface String { |
||||
replaceAll(regx: string, callback: (str: string) => void): string; |
||||
} |
@ -0,0 +1,61 @@
|
||||
export type Constructor<T> = new(...args: any[]) => T; |
||||
|
||||
/** |
||||
* 注册widget |
||||
*/ |
||||
export function shortcut() { |
||||
return function decorator<U>(Target: Constructor<U> & {xtype: string}): void { |
||||
BI.shortcut(Target.xtype, Target); |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* 注册model |
||||
*/ |
||||
export function model() { |
||||
return function decorator<U extends {new(...args:any[]):{}} & {xtype: string, context?: ReadonlyArray<string>}>(Target: U): void { |
||||
BI.model(Target.xtype, Target); |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* 类注册_store属性 |
||||
* @param Model model类 |
||||
* @param opts 额外条件 |
||||
*/ |
||||
export function store<T>(Model: Constructor<T> & {xtype: string}, opts: { props?(this: unknown): { [key: string]: unknown } } = {}) { |
||||
return function classDecorator<U extends {new(...args:any[]):{}}>(constructor:U) { |
||||
return class extends constructor { |
||||
_store() { |
||||
const props = opts.props ? opts.props.apply(this) : undefined; |
||||
|
||||
return BI.Models.getModel(Model.xtype, props); |
||||
} |
||||
}; |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Model基类 |
||||
*/ |
||||
export class Model<U extends {types?: {[key: string]: unknown} | {}, context?: ReadonlyArray<string>} = {}> extends Fix.Model { |
||||
// @ts-ignore this["computed"][key]为空
|
||||
model: Pick<{[key in keyof U["types"]]: U["types"][key]}, U["context"][number]> & {[key in keyof ReturnType<this["state"]>]: ReturnType<this["state"]>[key]} & {[key in keyof this["computed"]]: ReturnType<this["computed"][key]>}; |
||||
|
||||
store: this["actions"]; |
||||
|
||||
state(): {[key: string]: unknown} | {} { |
||||
return {}; |
||||
} |
||||
|
||||
context: U["context"]; |
||||
|
||||
actions:{[key: string]: (...args: any[]) => any}; |
||||
|
||||
childContext: ReadonlyArray<keyof (this["computed"] & ReturnType<this["state"]>)>; |
||||
|
||||
// @ts-ignore this["computed"][key]为空
|
||||
TYPE: Pick<{[key in keyof this["computed"]]: ReturnType<this["computed"][key]>} & {[key in keyof ReturnType<this["state"]>]: ReturnType<this["state"]>[key]}, this["childContext"][number]>; |
||||
|
||||
computed: {[key: string]: () => unknown} | {}; |
||||
} |
@ -0,0 +1,9 @@
|
||||
const path = require("path"); |
||||
module.exports = { |
||||
DEST: path.resolve(__dirname, "../dist"), |
||||
NODE_MODULES: path.resolve(__dirname, "../node_modules"), |
||||
PRIVATE: path.resolve(__dirname, "../private"), |
||||
BABEL_CONFIG: path.resolve(__dirname, "../babel.config.js"), |
||||
IE8_BABEL_CONFIG: path.resolve(__dirname, "../babel.config.ie8.js"), |
||||
TYPESCRIPT: path.resolve(__dirname, "../typescript"), |
||||
}; |
@ -0,0 +1,78 @@
|
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
||||
const autoprefixer = require("autoprefixer"); |
||||
|
||||
const dirs = require("./dirs"); |
||||
|
||||
const isBuilt4IE8 = process.env.BROWSER_VERSION === "ie8"; |
||||
|
||||
module.exports = { |
||||
entry: { |
||||
fineui: [ |
||||
...isBuilt4IE8 |
||||
? [ |
||||
"core-js/features/object/define-property", |
||||
"core-js/features/object/create", |
||||
"core-js/features/object/assign", |
||||
"core-js/features/array/for-each", |
||||
"core-js/features/array/index-of", |
||||
"core-js/features/function/bind", |
||||
"core-js/features/promise", |
||||
"core-js/features/object/get-own-property-symbols", |
||||
"core-js/features/string/replace", |
||||
// "core-js",
|
||||
] |
||||
: [ |
||||
"@babel/polyfill", |
||||
"es6-promise/auto", |
||||
], |
||||
"./typescript/index.ts", |
||||
], |
||||
}, |
||||
resolve: { |
||||
mainFields: ["module", "main"], |
||||
extensions: [".js", ".ts"], |
||||
}, |
||||
module: { |
||||
rules: [ |
||||
{ |
||||
test: /\.(js|ts)$/, |
||||
include: [dirs.NODE_MODULES, dirs.PRIVATE, dirs.TYPESCRIPT], |
||||
use: [{ |
||||
loader: "babel-loader", |
||||
options: { |
||||
configFile: isBuilt4IE8 ? dirs.IE8_BABEL_CONFIG : dirs.BABEL_CONFIG, |
||||
}, |
||||
}, { |
||||
loader: "source-map-loader", |
||||
options: { |
||||
enforce: "pre", |
||||
}, |
||||
}], |
||||
}, |
||||
{ |
||||
test: /\.(css|less)$/, |
||||
use: [ |
||||
MiniCssExtractPlugin.loader, |
||||
{ |
||||
loader: "css-loader", |
||||
options: { |
||||
url: false, |
||||
}, |
||||
}, |
||||
{ |
||||
loader: "postcss-loader", |
||||
options: { |
||||
plugins: [autoprefixer], |
||||
}, |
||||
}, |
||||
{ |
||||
loader: "less-loader", |
||||
options: { |
||||
relativeUrls: false, |
||||
}, |
||||
}, |
||||
], |
||||
}, |
||||
], |
||||
}, |
||||
}; |
@ -0,0 +1,50 @@
|
||||
const merge = require("webpack-merge"); |
||||
const path = require("path"); |
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
||||
const HtmlWebpackPlugin = require("html-webpack-plugin"); |
||||
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); |
||||
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin"); |
||||
|
||||
const dirs = require("./dirs"); |
||||
|
||||
const common = require("./webpack.common.js"); |
||||
|
||||
module.exports = merge(common, { |
||||
devtool: "eval-source-map", |
||||
output: { |
||||
path: dirs.DEST, |
||||
filename: "[name].[contenthash].js", |
||||
}, |
||||
devServer: { |
||||
contentBase: path.join(__dirname, ".."), |
||||
port: 9001, |
||||
liveReload: true, |
||||
}, |
||||
plugins: [ |
||||
new MiniCssExtractPlugin({ |
||||
path: dirs.DEST, |
||||
filename: "fineui.[contenthash].css", |
||||
}), |
||||
new HtmlWebpackPlugin({ |
||||
template: path.resolve(__dirname, "../index.html"), |
||||
chunks: ["fineui"], |
||||
chunksSortMode: "manual", |
||||
}), |
||||
new ForkTsCheckerWebpackPlugin({ |
||||
watch: ["./typescript"], |
||||
}), |
||||
new OptimizeCssAssetsPlugin({ |
||||
assetNameRegExp: /\.css$/g, |
||||
cssProcessor: require("cssnano"), |
||||
cssProcessorPluginOptions: { |
||||
preset: ["default", { |
||||
discardComments: { |
||||
removeAll: true, |
||||
}, |
||||
normalizeUnicode: false, |
||||
}], |
||||
}, |
||||
canPrint: true, |
||||
}), |
||||
], |
||||
}); |
@ -0,0 +1,78 @@
|
||||
const webpack = require("webpack"); |
||||
const merge = require("webpack-merge"); |
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
||||
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); |
||||
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin"); |
||||
const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); |
||||
|
||||
const isBuilt4IE8 = process.env.BROWSER_VERSION === "ie8"; |
||||
|
||||
const dirs = require("./dirs"); |
||||
|
||||
const common = require("./webpack.common.js"); |
||||
|
||||
module.exports = merge.smart(common, { |
||||
mode: "production", |
||||
optimization: { |
||||
minimizer: [ |
||||
new UglifyJsPlugin({ |
||||
parallel: true, |
||||
sourceMap: true, |
||||
uglifyOptions: { |
||||
ie8: true, |
||||
output: { |
||||
comments: false, |
||||
}, |
||||
} |
||||
}) |
||||
] |
||||
}, |
||||
|
||||
devtool: "hidden-source-map", |
||||
|
||||
output: { |
||||
path: dirs.DEST, |
||||
filename: isBuilt4IE8 ? "ie.fineui.js" : "es5.fineui.js", |
||||
}, |
||||
|
||||
plugins: [ |
||||
new MiniCssExtractPlugin({ |
||||
path: dirs.DEST, |
||||
filename: "es5.fineui.css", |
||||
}), |
||||
new webpack.BannerPlugin({ |
||||
banner: `time: ${new Date().toLocaleString()}`, |
||||
}), |
||||
new ForkTsCheckerWebpackPlugin({ |
||||
}), |
||||
new OptimizeCssAssetsPlugin({ |
||||
assetNameRegExp: /\.css$/g, |
||||
cssProcessor: require("cssnano"), |
||||
cssProcessorPluginOptions: { |
||||
preset: ["default", { |
||||
discardComments: { |
||||
removeAll: true, |
||||
}, |
||||
normalizeUnicode: false, |
||||
}], |
||||
}, |
||||
canPrint: true, |
||||
}), |
||||
], |
||||
|
||||
module: { |
||||
rules: [ |
||||
{ |
||||
test: /\.(css|less)$/, |
||||
use: [ |
||||
{ |
||||
loader: "postcss-loader", |
||||
options: { |
||||
plugins: [], |
||||
}, |
||||
}, |
||||
], |
||||
}, |
||||
], |
||||
}, |
||||
}); |
Loading…
Reference in new issue