Skip to content

Commit

Permalink
chore: 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maplor committed Mar 4, 2021
1 parent 5dc492e commit d47a211
Show file tree
Hide file tree
Showing 280 changed files with 32,801 additions and 24,754 deletions.
75 changes: 75 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
############################
# NPM files
############################
**/node_modules
**/bower_components
node_modules
bower_components
npm-debug.log


############################
# Temp files
############################
temp
tmp
.tmp
*.swo
*.swp
*.swn
*.swm
*.diff
*.log
*.patch
*.bak
*.log
*.iml
*.ipr
*.iws
*.out
*.gz
*#
*~
~*


############################
# Editor & OS files
############################
.idea
.DS_STORE
.Trashes
.project
.rebooted
.*proj
Thumbs.db
ehthumbs.db
Icon?
nbproject


############################
# Report files
############################
coverages
coverage
reports
report
lib-cov
html-report
nohup.out
out
logs
log


############################
# Other
############################
.node_history
.svn
**/tms
.nodejs-cache
.node-diamond-client-cache
node_hsf_config_snapshots
run
2 changes: 1 addition & 1 deletion .babelrc → .storybook/.babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"presets": [
"babel-preset-react",
["babel-preset-env", { "loose": true }],
"babel-preset-env",
"babel-preset-stage-0"
],
"plugins": [
Expand Down
10 changes: 6 additions & 4 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const path = require('path');
const webpack = require('webpack');
const packageInfo = require('../package');
const srcPath = path.resolve(__dirname, '../components');
const srcPath = path.resolve(__dirname, '../src');

module.exports = {
plugins: [
Expand Down Expand Up @@ -36,14 +36,16 @@ module.exports = {
},
}],
},
{
test: /\.(ts|tsx)$/,
use: ['awesome-typescript-loader'],
}
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
alias: {
'@alicloud/cloud-charts': srcPath,
'@alicloud/cloud-charts/lib': srcPath,
'@antv/data-set$': path.resolve(__dirname, '../components/common/dataSet'),
'@antv/data-set/lib': '@antv/data-set/lib'
}
},
};
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CloudCharts

![](https://img.shields.io/npm/v/@alicloud/cloud-charts?color=%23ff8200)

![CloudCharts](https://img.alicdn.com/tfs/TB1FfqtTGL7gK0jSZFBXXXZZpXa-2764-1488.png)

面向中后台的开箱即用图表库,让前端图表更简单。
Expand Down
4 changes: 4 additions & 0 deletions abc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "ice-app",
"builder": "@ali/builder-ice-app"
}
197 changes: 197 additions & 0 deletions build.after.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
// const Config = require('webpack-chain');
const { getWebpackConfig } = require('build-scripts-config');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const packageInfo = require('./package.json');

/** 自定义构建脚本 - 后置 */
module.exports = ({ context, onGetWebpackConfig, registerTask, registerCliOption }) => {
const { command, commandArgs, rootDir, userConfig } = context;
const { library, libraryTarget = 'umd', libraryExport } = userConfig;

function setBuildConfig(config, theme = 'index') {
// 调整构建目录
config.output
.path(path.resolve(rootDir, 'build'))
.filename('[name].js')
.publicPath('./build/')

// 去除默认字体资源配置
config.module.rules
.delete('woff2')
.delete('ttf')
.delete('eot')
.delete('svg');

// 自定义字体资源配置
config.module
.rule('font').test(/\.(woff|woff2|eot|ttf|otf|svg)((\?|#).*)?$/)
.use('file').loader('file-loader').options({
name: '[name].[ext]',
publicPath: './',
});

// 全局变量
config
.plugin('DefinePlugin')
.use(webpack.DefinePlugin, [{
__VERSION__: JSON.stringify(packageInfo.version),
__THEME__: JSON.stringify(theme),
}]);

// 插件部分,需要 externals @alicloud/cloud-charts 本身
config.externals({
react: {
root: 'React',
commonjs: 'react',
commonjs2: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'react-dom',
},
'@alicloud/cloud-charts': {
root: userConfig.library,
commonjs2: '@alicloud/cloud-charts',
commonjs: '@alicloud/cloud-charts',
amd: '@alicloud/cloud-charts'
},
});
}

registerCliOption({
name: 'online',
commands: ['start'],
});

registerCliOption({
name: 'analyzer',
commands: ['build'],
});

// 在线代理
if (commandArgs.online) {
const onlineConfig = getWebpackConfig('development');
onlineConfig.target('web');
onlineConfig.context(rootDir);

setBuildConfig(onlineConfig);

onlineConfig.output
.library(library)
.libraryExport(libraryExport)
.libraryTarget(libraryTarget);

onlineConfig
.entry('index')
.add(path.resolve(rootDir, 'src/index.scss'))
.add(path.resolve(rootDir, 'src/index.ts'));

registerTask('online-web', onlineConfig);
}

// 插件部分
if (!commandArgs.analyzer) {
const mode = command === 'start' ? 'development' : 'production';
const pluginsConfig = getWebpackConfig(mode);
pluginsConfig.target('web');
pluginsConfig.context(rootDir);

setBuildConfig(pluginsConfig);

pluginsConfig.output
.library(`${library}[name]`)
.libraryExport(libraryExport)
.libraryTarget(libraryTarget);

const pluginPath = path.resolve(rootDir, './src/plugins');
const plugins = fs.readdirSync(pluginPath);
plugins.forEach(function (plugin) {
var componentStat = fs.lstatSync(pluginPath + '/' + plugin);
if (!componentStat.isDirectory()) {
return;
}

pluginsConfig
.entry(plugin)
.add('./src/plugins/' + plugin + '/index.tsx');
});

registerTask('plugins', pluginsConfig);
}


// 调整 umd 包 webpack 配置
// config 为 webpack-chain 实例
onGetWebpackConfig('component-dist', config => {
setBuildConfig(config);

if (commandArgs.analyzer) {
config
.plugin('analyzer')
.use(BundleAnalyzerPlugin);
}
});

// onGetWebpackConfig(config => {
// console.log(Config.toString(config.toConfig()));
// });

// 主题包
if (!commandArgs.online && !commandArgs.analyzer) {
const themeConfig = getWebpackConfig('production');
themeConfig.target('web');
themeConfig.context(rootDir);

setBuildConfig(themeConfig, 'dark');

themeConfig.module.rule('scss').use('sass-loader').tap(options => {
return {
...options,
// additionalData: (content, loaderContext) => {
// // More information about available properties https://webpack.js.org/api/loaders/
// const { resourcePath, rootContext } = loaderContext;
// const relativePath = path.relative(rootContext, resourcePath);
// console.log('relativePath', relativePath);
// return content;
// // if (relativePath === "styles/foo.scss") {
// // return "$value: 100px;" + content;
// // }
// //
// // return "$value: 200px;" + content;
// },
// 由于 build-plugin-component -> build-scripts-config -> sass-loader 版本是 8.x,所以使用 prependData。
// 如果更新了依赖版本,可以用 additionalData
prependData: (loaderContext) => {
// More information about available properties https://webpack.js.org/api/loaders/
const { resourcePath, rootContext } = loaderContext;
// const relativePath = path.relative(rootContext, resourcePath);

const themePath = path.relative(resourcePath, path.join(rootContext, './src/themes/dark.scss'));
// console.log('relativePath', relativePath, resourcePath);
// if (relativePath === 'src/index.scss') {
// return '@import "themes/dark";'
// }
return `@import "${themePath.slice(3)}"; `;
},
}
})

themeConfig.output
.library(library)
.libraryExport(libraryExport)
.libraryTarget(libraryTarget);

themeConfig
.entry('dark')
.add(path.resolve(rootDir, 'src/index.scss'))
.add(path.resolve(rootDir, 'src/index.ts'));

registerTask('theme-dark', themeConfig);
}
};
Loading

0 comments on commit d47a211

Please sign in to comment.