From 7bc0c1977713be424df950c7b5b826d72bf6d144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BC=80=E6=9C=97?= Date: Thu, 10 Oct 2019 14:38:33 +0800 Subject: [PATCH] fix: Bundle sass to css --- README.md | 9 ++++----- babel.config.js | 18 +++++++++++++++--- docs/content/get-started/introduction.mdx | 9 ++++----- docs/src/components/TopBar/index.js | 11 +++++++++++ package.json | 11 +++++++---- scripts/build-copy.ts | 5 ++--- src/style/bootstrap.scss | 2 +- yarn.lock | 5 +++++ 8 files changed, 49 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c6cc5182..7595c862 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ Add in package.json ```bash yarn add wizard-ui -# sass dep && loader -yarn add --dev node-sass style-loader css-loader sass-loader +# css loader +yarn add --dev style-loader css-loader # react bootstrap font dev yarn add --dev url-loader file-loader ``` @@ -31,11 +31,10 @@ if you not use [create-react-app](https://github.com/facebook/create-react-app), ```js { - test: /\.(css|scss)$/, + test: /\.css$/, use: [ 'style-loader', 'css-loader', - 'sass-loader' ] }, { @@ -51,7 +50,7 @@ if you not use [create-react-app](https://github.com/facebook/create-react-app), ### Global style ```jsx -import 'wizard-ui/lib/style/index.scss'; +import 'wizard-ui/lib/style/index.css'; ``` ### Usage diff --git a/babel.config.js b/babel.config.js index b7ba82e3..45eb5530 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,7 +2,8 @@ module.exports = api => { const env = api.env(); console.log('env', env); const lib = env === 'lib'; - return { + const esm = env === 'esm'; + let result = { presets: [ '@babel/preset-react', '@babel/preset-typescript', @@ -25,17 +26,28 @@ module.exports = api => { { removeImport: true, }, - ], + ] ], ignore: [ '**/*.test.tsx', '**/types', '**/interface.tsx', '**/global.d.ts', - // '**/setupEnzyme.ts' ], // minified: true, // comments: false, // compact: true, + }; + + if (lib || esm) { + result.plugins.push([ + 'transform-rename-import', + { + "original": '^(.+?)\\.scss$', + "replacement": '$1.css' + } + ]) } + + return result; } diff --git a/docs/content/get-started/introduction.mdx b/docs/content/get-started/introduction.mdx index 53223b4e..962b2447 100644 --- a/docs/content/get-started/introduction.mdx +++ b/docs/content/get-started/introduction.mdx @@ -9,19 +9,18 @@ Wizard UI 是基于 React 和 Typescript 开发的 UI 组件库。 ```bash # install yarn add wizard-ui -# sass dep && loader -yarn add --dev node-sass style-loader css-loader sass-loader +# css loader +yarn add --dev style-loader css-loader # react bootstrap font dev yarn add --dev url-loader file-loader ``` 需要设置 `webpack config`: ```js { - test: /\.(css|scss)$/, + test: /\.css$/, use: [ 'style-loader', 'css-loader', - 'sass-loader' ] }, { @@ -47,7 +46,7 @@ ReactDOM.render( ### 全局样式 ```jsx -import 'wizard-ui/lib/style/index.scss'; +import 'wizard-ui/lib/style/index.css'; ``` ## 单元测试 diff --git a/docs/src/components/TopBar/index.js b/docs/src/components/TopBar/index.js index 9c432098..5721a2fd 100644 --- a/docs/src/components/TopBar/index.js +++ b/docs/src/components/TopBar/index.js @@ -95,6 +95,17 @@ const TopBar = (props) => { +