Skip to content

Commit

Permalink
feat: style import from index-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaosansiji committed Jan 19, 2022
1 parent b1898a4 commit 45d8c22
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
64 changes: 31 additions & 33 deletions script/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const banner = `/**
* @license ${pkg.license}
*/
`;
const input = 'src/index.ts';
const input = 'src/index-lib.ts';
const inputList = [
'src/**/*.ts',
'src/**/*.jsx',
Expand Down Expand Up @@ -70,18 +70,18 @@ const getPlugins = ({

// css
if (extractOneCss) {
plugins.push(postcss({
extract: `${isProd ? `${name}.min` : name}.css`,
minimize: isProd,
sourceMap: true,
extensions: ['.sass', '.scss', '.css', '.less'],
}));
plugins.push(
postcss({
extract: `${isProd ? `${name}.min` : name}.css`,
minimize: isProd,
sourceMap: true,
extensions: ['.sass', '.scss', '.css', '.less'],
}),
);
} else if (extractMultiCss) {
plugins.push(
staticImport({
include: [
'src/**/style/css.js',
],
include: ['src/**/style/css.js'],
}),
ignoreImport({
include: ['src/*/style/*', 'src/*/*/style/*'],
Expand All @@ -93,10 +93,7 @@ const getPlugins = ({
} else {
plugins.push(
staticImport({
include: [
'src/**/style/index.js',
'src/_common/style/web/**/*.less',
],
include: ['src/**/style/index.js', 'src/_common/style/web/**/*.less'],
}),
ignoreImport({
include: ['src/*/style/*'],
Expand All @@ -106,22 +103,26 @@ const getPlugins = ({
}

if (env) {
plugins.push(replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify(env),
},
}));
plugins.push(
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify(env),
},
}),
);
}

if (isProd) {
plugins.push(terser({
output: {
/* eslint-disable */
ascii_only: true,
/* eslint-enable */
},
}));
plugins.push(
terser({
output: {
/* eslint-disable */
ascii_only: true,
/* eslint-enable */
},
}),
);
}

return plugins;
Expand All @@ -130,10 +131,7 @@ const getPlugins = ({
/** @type {import('rollup').RollupOptions} */
const cssConfig = {
input: ['src/**/style/index.js'],
plugins: [
multiInput(),
styles({ mode: 'extract' }),
],
plugins: [multiInput(), styles({ mode: 'extract' })],
output: {
banner,
dir: 'es/',
Expand All @@ -159,7 +157,7 @@ const libConfig = {
// 按需加载组件 带 css 样式
/** @type {import('rollup').RollupOptions} */
const esConfig = {
input: inputList,
input: inputList.concat('!src/index-lib.ts'),
// 为了保留 style/css.js
treeshake: false,
external: externalDeps.concat(externalPeerDeps),
Expand All @@ -175,7 +173,7 @@ const esConfig = {

// 按需加载组件 带原始 less 文件,可定制主题
const esmConfig = {
input: inputList,
input: inputList.concat('!src/index-lib.ts'),
// 为了保留 style/index.js
treeshake: false,
external: externalDeps.concat(externalPeerDeps),
Expand Down
15 changes: 15 additions & 0 deletions src/index-lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import './style';

const ENV = process.env.NODE_ENV;
if (
ENV !== 'test' &&
ENV !== 'production' &&
typeof console !== 'undefined' &&
console.warn && // eslint-disable-line no-console
typeof window !== 'undefined'
) {
// eslint-disable-next-line no-console
console.warn('You are using a whole package of TDesign!');
}

export * from './index';

0 comments on commit 45d8c22

Please sign in to comment.