Skip to content

Commit

Permalink
fix: the cjs files built using less imports
Browse files Browse the repository at this point in the history
  • Loading branch information
awmleer committed Sep 10, 2021
1 parent c8e8d39 commit 6e9e1a6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .babelrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"plugins": [
"babel-plugin-transform-async-to-promises",
["replace-import-extension", { "extMapping": { ".less": ".css" } }]
"./babel-transform-less-to-css"
],
"ignore": ["**/demos"]
}
14 changes: 14 additions & 0 deletions babel-transform-less-to-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = function () {
return {
visitor: {
ImportDeclaration(path, source) {
if (path.node.source.value.endsWith('.less')) {
path.node.source.value = path.node.source.value.replace(
/\.less$/,
'.css'
)
}
},
},
}
}
24 changes: 11 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,18 @@ function copyAssets() {
.pipe(gulp.dest('lib/cjs/assets'))
}

function tsCJS() {
const tsProject = ts({
...tsconfig.compilerOptions,
module: 'CommonJS',
})
function buildCJS() {
return gulp
.src(['src/**/*.{ts,tsx}'], {
ignore: ['**/demos/**/*', '**/tests/**/*'],
})
.pipe(tsProject)
.pipe(babel())
.src(['lib/es/**/*.js'])
.pipe(
babel({
'plugins': ['@babel/plugin-transform-modules-commonjs'],
})
)
.pipe(gulp.dest('lib/cjs/'))
}

function tsES() {
function buildES() {
const tsProject = ts({
...tsconfig.compilerOptions,
module: 'ESNext',
Expand All @@ -68,7 +65,7 @@ function tsES() {
.pipe(gulp.dest('lib/es/'))
}

function tsDeclaration() {
function buildDeclaration() {
const tsProject = ts({
...tsconfig.compilerOptions,
module: 'ESNext',
Expand Down Expand Up @@ -176,7 +173,8 @@ exports.umdWebpack = umdWebpack

exports.default = gulp.series(
clean,
gulp.parallel(tsCJS, tsES, tsDeclaration, buildStyle),
buildES,
gulp.parallel(buildCJS, buildDeclaration, buildStyle),
copyAssets,
copyMetaFiles,
generatePackageJSON,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"@babel/cli": "^7.15.4",
"@babel/core": "^7.15.5",
"@babel/plugin-transform-modules-commonjs": "^7.15.4",
"@babel/preset-env": "^7.15.4",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
Expand All @@ -48,7 +49,6 @@
"@typescript-eslint/parser": "^4.31.0",
"babel-loader": "^8.2.2",
"babel-plugin-import": "^1.13.3",
"babel-plugin-replace-import-extension": "^1.1.1",
"babel-plugin-transform-async-to-promises": "^0.8.15",
"css-loader": "^6.2.0",
"del": "^5.1.0",
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3761,6 +3761,7 @@ __metadata:
"@ant-design/icons": ^4.6.4
"@babel/cli": ^7.15.4
"@babel/core": ^7.15.5
"@babel/plugin-transform-modules-commonjs": ^7.15.4
"@babel/preset-env": ^7.15.4
"@babel/preset-react": ^7.14.5
"@babel/preset-typescript": ^7.15.0
Expand All @@ -3782,7 +3783,6 @@ __metadata:
antd-mobile-v5-count: ^1.0.1
babel-loader: ^8.2.2
babel-plugin-import: ^1.13.3
babel-plugin-replace-import-extension: ^1.1.1
babel-plugin-transform-async-to-promises: ^0.8.15
classnames: ^2.3.1
css-loader: ^6.2.0
Expand Down Expand Up @@ -4296,13 +4296,6 @@ __metadata:
languageName: node
linkType: hard

"babel-plugin-replace-import-extension@npm:^1.1.1":
version: 1.1.1
resolution: "babel-plugin-replace-import-extension@npm:1.1.1"
checksum: ac029093db7d995ce2c7b080be75e94d662fb18c0960f98ce7909d04a835d7816a4f870b1a591f4a179efd4c1f9e4825e4e7fcec97c297e2b39032c154433a72
languageName: node
linkType: hard

"babel-plugin-transform-async-to-promises@npm:^0.8.15":
version: 0.8.15
resolution: "babel-plugin-transform-async-to-promises@npm:0.8.15"
Expand Down

0 comments on commit 6e9e1a6

Please sign in to comment.