-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
280 changed files
with
32,801 additions
and
24,754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "ice-app", | ||
"builder": "@ali/builder-ice-app" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
Oops, something went wrong.