diff --git a/packages/fes-preset-built-in/package.json b/packages/fes-preset-built-in/package.json index c18db96d..9f3f43d0 100644 --- a/packages/fes-preset-built-in/package.json +++ b/packages/fes-preset-built-in/package.json @@ -36,6 +36,7 @@ "html-webpack-plugin": "^3.2.0", "html-webpack-tags-plugin": "2.0.17", "vue-loader": "^16.1.2", - "webpack-bundle-analyzer": "4.3.0" + "webpack-bundle-analyzer": "4.3.0", + "babel-plugin-import": "1.13.3" } } diff --git a/packages/fes-preset-built-in/src/index.js b/packages/fes-preset-built-in/src/index.js index 211a97a1..e225229a 100644 --- a/packages/fes-preset-built-in/src/index.js +++ b/packages/fes-preset-built-in/src/index.js @@ -15,6 +15,7 @@ export default function () { require.resolve('./plugins/features/analyze'), require.resolve('./plugins/features/autoprefixer'), require.resolve('./plugins/features/base'), + require.resolve('./plugins/features/babelPluginImport'), require.resolve('./plugins/features/chainWebpack'), require.resolve('./plugins/features/chunks'), require.resolve('./plugins/features/cssLoader'), diff --git a/packages/fes-preset-built-in/src/plugins/features/babelPluginImport.js b/packages/fes-preset-built-in/src/plugins/features/babelPluginImport.js new file mode 100644 index 00000000..76dfd763 --- /dev/null +++ b/packages/fes-preset-built-in/src/plugins/features/babelPluginImport.js @@ -0,0 +1,20 @@ +export default (api) => { + api.describe({ + key: 'babelPluginImport', + config: { + schema(joi) { + return joi.array(); + } + } + }); + + api.modifyBabelOpts((babelOpts) => { + if (api.config.babelPluginImport) { + api.config.babelPluginImport.forEach((config) => { + babelOpts.plugins.push(['import', config]); + }); + } + + return babelOpts; + }); +}; diff --git a/packages/fes-preset-built-in/src/plugins/misc/route/index.js b/packages/fes-preset-built-in/src/plugins/misc/route/index.js index 13869371..390930ce 100644 --- a/packages/fes-preset-built-in/src/plugins/misc/route/index.js +++ b/packages/fes-preset-built-in/src/plugins/misc/route/index.js @@ -101,7 +101,7 @@ const genRoutes = function (parentRoutes, path, parentRoutePath, config) { path: routePath, component: componentPath, name: routeName, - meta: routeMetaBlock.content ? JSON.parse(routeMetaBlock.content) : {} + meta: routeMetaBlock?.content ? JSON.parse(routeMetaBlock.content) : {} }); } } else { @@ -109,7 +109,7 @@ const genRoutes = function (parentRoutes, path, parentRoutePath, config) { path: routePath, component: componentPath, name: routeName, - meta: routeMetaBlock.content ? JSON.parse(routeMetaBlock.content) : {} + meta: routeMetaBlock?.content ? JSON.parse(routeMetaBlock.content) : {} }); } }