babel-plugin-transform-cx-imports
Advanced tools
Comparing version 16.12.2 to 17.3.1
12
index.js
@@ -23,3 +23,3 @@ "use strict"; | ||
if (src.indexOf("cx/") == 0) { | ||
if (src.indexOf("cx/") == 0 && src.indexOf('cx/src/') != 0) { | ||
var remainder = src.substring(3); | ||
@@ -30,2 +30,4 @@ | ||
console.log(remainder); | ||
path.node.specifiers.forEach(function (s) { | ||
@@ -36,6 +38,6 @@ var expanded = remainder + '/' + s.imported.name; | ||
if (srcFile.js) | ||
imports.push(t.importDeclaration([s], t.stringLiteral('cx-core/' + srcFile.js))); | ||
imports.push(t.importDeclaration([s], t.stringLiteral('cx/' + srcFile.js))); | ||
if (srcFile.scss && importScss) { | ||
imports.push(t.importDeclaration([], t.stringLiteral('cx-core/' + srcFile.scss))); | ||
imports.push(t.importDeclaration([], t.stringLiteral('cx/' + srcFile.scss))); | ||
} | ||
@@ -50,6 +52,2 @@ } | ||
} | ||
else { | ||
//cx-core => cx | ||
path.replaceWith(t.importDeclaration(path.node.specifiers, t.stringLiteral("cx-core/" + remainder))); | ||
} | ||
} | ||
@@ -56,0 +54,0 @@ } |
This package is a part of the Cx framework, which is available under | ||
different licensing options depending on the nature of your project. | ||
For more information, please refer to http://cx.codaxy.com. | ||
For more information, please refer to https://cxjs.io. | ||
{ | ||
"name": "babel-plugin-transform-cx-imports", | ||
"version": "16.12.2", | ||
"description": "Rewrite imports from Cx for simplicity and optimal output size.", | ||
"version": "17.3.1", | ||
"description": "Rewrite Cx imports for simplicity and optimal output size.", | ||
"repository": "https://github.com/codaxy/cx", | ||
@@ -6,0 +6,0 @@ "author": "Marko Stijak", |
# babel-plugin-transform-cx-imports | ||
This plugin does three things: | ||
What this is plugin is used for? | ||
1. Rewrites Cx imports to use `src` files which may result with smaller builds: | ||
1. rewrites `cx` based imports to `cx-core`. E.g. | ||
`import { TextField} from 'cx/widgets'` becomes `import { TextField} from 'cx-core/widgets'`. | ||
2. optionally rewrites imports to use `src` files: | ||
`import { TextField} from 'cx/widgets'` becomes `import { TextField} from 'cx-core/src/ui/form/TextField'`. | ||
`import { TextField} from 'cx/widgets'` | ||
3. optionally includes SCSS files for imported components. E.g. | ||
`import { TextField} from 'cx/widgets'` adds also `import 'cx-core/src/ui/form/TextField.scss'`. | ||
becomes | ||
`import { TextField} from 'cx/src/form/TextField'`. | ||
2. Include SCSS files for imported components (experimental). | ||
`import { TextField} from 'cx/widgets'` | ||
adds also | ||
`import 'cx/src/form/TextField.scss'`. | ||
### Usage | ||
Standard: | ||
``` | ||
//.babelrc | ||
"plugins": [ | ||
"transform-cx-imports" | ||
] | ||
``` | ||
To use src files, use: | ||
@@ -32,3 +31,3 @@ | ||
``` | ||
Note that if using src files, your babel/webpack configuration should whitelist `cx-core` path. | ||
Note that if using src files, your babel/webpack configuration should whitelist `cx` path. | ||
@@ -35,0 +34,0 @@ Optionally, if you want to include .scss files, use: |
25
test.js
@@ -16,3 +16,3 @@ "use strict"; | ||
describe.only('babel-plugin-transform-cx-imports', function() { | ||
describe('babel-plugin-transform-cx-imports', function() { | ||
@@ -30,13 +30,2 @@ it("skips non-cx import", function () { | ||
it("rewrites cx into cx-core", function () { | ||
let code = `import { Widget } from "cx/ui"`; | ||
let output = babel.transform(code, { | ||
plugins: [plugin] | ||
}).code; | ||
assert.equal(unwrap(output), 'import { Widget } from "cx-core/ui"'); | ||
}); | ||
it("supports multiple imports", function () { | ||
@@ -50,3 +39,3 @@ | ||
assert.equal(unwrap(output), 'import { Widget, VDOM } from "cx-core/ui"'); | ||
assert.equal(unwrap(output), 'import { Widget, VDOM } from "cx/ui"'); | ||
}); | ||
@@ -62,3 +51,3 @@ | ||
assert.equal(unwrap(output), 'import { TextField } from "cx-core/src/widgets/form/TextField.js"'); | ||
assert.equal(unwrap(output), 'import { TextField } from "cx/src/widgets/form/TextField.js"'); | ||
}); | ||
@@ -75,4 +64,4 @@ | ||
assert.deepEqual(lines(output), [ | ||
'import { TextField } from "cx-core/src/widgets/form/TextField.js";', | ||
'import "cx-core/src/widgets/form/TextField.scss"' | ||
'import { TextField } from "cx/src/widgets/form/TextField.js";', | ||
'import "cx/src/widgets/form/TextField.scss"' | ||
]); | ||
@@ -90,6 +79,6 @@ }); | ||
assert.deepEqual(lines(output), [ | ||
'import { Text } from "cx-core/src/ui/Text.js";', | ||
'import { TextField } from "cx-core/src/widgets/form/TextField.js"' | ||
'import { Text } from "cx/src/ui/Text.js";', | ||
'import { TextField } from "cx/src/widgets/form/TextField.js"' | ||
]); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6517
96
41