Skip to content

Commit

Permalink
Merge pull request #43 from ice-lab/fix-babel-config
Browse files Browse the repository at this point in the history
fix: deep copy babelConfig from webpack config
  • Loading branch information
daysai authored Aug 22, 2019
2 parents d6a963a + 7a0a8ce commit b7972ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/ice-plugin-component/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const fse = require('fs-extra');
const clonedeep = require('lodash.clonedeep');
const { getPkgJSONSync } = require('./utils/pkgJson');
const getDemoDir = require('./utils/getDemoDir');
const getDemos = require('./utils/getDemos');
Expand All @@ -18,12 +19,14 @@ module.exports = ({ context, chainWebpack, onHook, log }, opts = {}) => {
const { command, rootDir, reRun } = context;
const { type = 'fusion' } = opts;
const pkg = getPkgJSONSync(rootDir);
// store babel config
let babelConfig;
// store webpack chain config
let webpackChain;
// check adaptor folder
const hasAdaptor = fse.existsSync(path.join(rootDir, 'adaptor')) && type === 'fusion';

chainWebpack((config) => {
// expose config
webpackChain = config;
// add @babel/plugin-transform-runtime
// @babel/preset-env modules: commonjs
configBabel(config, {
Expand All @@ -49,7 +52,7 @@ module.exports = ({ context, chainWebpack, onHook, log }, opts = {}) => {
],
});
// get babel config for component compile
babelConfig = config.module.rule('jsx').use('babel-loader').get('options');
const babelConfig = clonedeep(config.module.rule('jsx').use('babel-loader').get('options'));
// babel option do not known cacheDirectory
delete babelConfig.cacheDirectory;

Expand All @@ -76,6 +79,9 @@ module.exports = ({ context, chainWebpack, onHook, log }, opts = {}) => {
// build src and umd adpator after demo build
onHook('afterBuild', () => {
process.env.BUILD_AGAIN = true;
// get babel config after all plugin had been excuted
const babelConfig = clonedeep(webpackChain.module.rule('jsx').use('babel-loader').get('options'));
delete babelConfig.cacheDirectory;
// component buildSrc
buildSrc({ babelConfig, rootDir, log });
modifyPkgHomePage(pkg, rootDir);
Expand Down
1 change: 1 addition & 0 deletions packages/ice-plugin-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ice-npm-utils": "^1.0.3",
"js-yaml": "^3.13.1",
"loader-utils": "^1.2.3",
"lodash.clonedeep": "^4.5.0",
"marked": "^0.6.2",
"npmlog": "^4.1.2",
"prismjs": "^1.16.0",
Expand Down

0 comments on commit b7972ee

Please # to comment.