Skip to content

Commit 190f273

Browse files
committed
feat: add js file to imported style file
1 parent 6fd05e2 commit 190f273

File tree

8 files changed

+4720
-3905
lines changed

8 files changed

+4720
-3905
lines changed

.babelrc.js

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
2-
module.exports = {
3-
presets: [
4-
[
5-
"@babel/preset-env",
6-
{
7-
modules: false
8-
}
9-
],
10-
"@babel/preset-react",
11-
"@babel/preset-typescript"
1+
const config = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
modules: false,
7+
},
128
],
13-
plugins: [
14-
"@babel/plugin-transform-runtime",
15-
[
16-
"@babel/plugin-proposal-decorators",
9+
'@babel/preset-react',
10+
'@babel/preset-typescript',
11+
],
12+
plugins:
13+
process.env.NODE_ENV === 'production'
14+
? [
15+
'./css-plugin',
16+
[
17+
'@babel/plugin-proposal-decorators',
18+
{
19+
legacy: true,
20+
},
21+
],
22+
'@babel/plugin-proposal-class-properties',
23+
'@babel/plugin-proposal-object-rest-spread',
24+
'@babel/plugin-transform-modules-commonjs',
25+
]
26+
: [
27+
[
28+
'@babel/plugin-proposal-decorators',
1729
{
18-
legacy: true
19-
}
30+
legacy: true,
31+
},
32+
],
33+
'@babel/plugin-proposal-class-properties',
34+
'@babel/plugin-proposal-object-rest-spread',
35+
'@babel/plugin-transform-modules-commonjs',
2036
],
21-
"@babel/plugin-proposal-class-properties",
22-
"@babel/plugin-proposal-object-rest-spread",
23-
"@babel/plugin-transform-modules-commonjs"
24-
]
2537
};
38+
module.exports = config;

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ debug.log
88
yarn-error.log
99
package-lock.json
1010
dist/
11-
gulpfile.js
11+
gulpfile.js
12+
index.tsx

css-plugin.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const t = require('@babel/types');
2+
module.exports = function() {
3+
return {
4+
visitor: {
5+
ImportDeclaration(path) {
6+
const { node } = path;
7+
if (!node) return;
8+
const {
9+
source: { value: libName },
10+
} = node;
11+
if (libName === './style.scss') {
12+
path.replaceWith(t.importDeclaration([], t.stringLiteral('./style.css')));
13+
}
14+
},
15+
},
16+
};
17+
};

gulpfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const del = require('del');
66
const ts = require('gulp-typescript');
77
const cleanCSS = require('gulp-clean-css');
88
const rename = require('gulp-rename');
9-
// const tsProject = ts.createProject('./tsconfig.build.json');
9+
const babel = require('gulp-babel');
1010

1111
function outputStyleTask() {
1212
return src(['src/components/**/*.scss'])
@@ -56,8 +56,8 @@ function jsForScss(data) {
5656
}
5757
function jsForCss(data) {
5858
return src('src/index.tsx')
59-
.pipe(rename('style.tsx'))
60-
.pipe(ts({ target: 'ES5' }))
59+
.pipe(rename('css.tsx'))
60+
.pipe(babel())
6161
.pipe(dest('lib/' + String(data) + '/style/'));
6262
}
6363
exports.default = series(clean, parallel(outputStyleTask, globalSass), globalCss);

0 commit comments

Comments
 (0)