diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..f42b04d --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry = "https://npm.docdoc.pro/" \ No newline at end of file diff --git a/README.md b/README.md index f42512d..6121f9e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,11 @@ First, follow craco's Then, install `craco-linaria` and [Linaria][]: ```bash -$ npm install --save-dev craco-linaria linaria +$ yarn add -D craco-linaria @linaria/core @linaria/babel-preset @linaria/webpack-loader + +// or + +$ npm install --save-dev craco-linaria @linaria/core @linaria/babel-preset @linaria/webpack-loader ``` ## Usage diff --git a/package.json b/package.json index 4f960cd..a8ec064 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "craco-linaria", - "version": "1.1.2", + "version": "3.0.4", "description": "A craco plugin to use Linaria zero-runtime CSS in JS library in a create react app.", "keywords": [ "craco", @@ -91,7 +91,10 @@ }, "peerDependencies": { "@craco/craco": "5.x", - "linaria": "1.x", + "@linaria/babel-preset": "3.x", + "@babel/preset-typescript": "7.x", + "@linaria/core": "3.x", + "@linaria/webpack-loader": "3.x", "react-scripts": "3.x" }, "dependencies": { diff --git a/src/__tests__/index.js b/src/__tests__/index.js index e9ad450..a9cfde7 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -10,7 +10,7 @@ describe('craco-linaria plugin', () => { ).toMatchInlineSnapshot(` Object { "transform": Object { - "^.+\\\\.(js|jsx|ts|tsx)$": "${process.cwd()}/src/babelTransform.js", + "^.+\\\\.(js|jsx|mjs|cjs|ts|tsx)$": "${process.cwd()}/src/babelTransform.js", }, } `) @@ -73,12 +73,12 @@ describe('craco-linaria plugin', () => { "loader": "/babel-loader/", "options": Object { "presets": Array [ - "linaria/babel", + "@linaria/babel-preset", ], }, }, Object { - "loader": "linaria/loader", + "loader": "@linaria/webpack-loader", "options": Object { "babelOptions": Object { "presets": Array [], diff --git a/src/babelTransform.js b/src/babelTransform.js index 9e532a7..69f2ec2 100644 --- a/src/babelTransform.js +++ b/src/babelTransform.js @@ -1,7 +1,16 @@ const babelJest = require('babel-jest') module.exports = babelJest.createTransformer({ - presets: [require.resolve('babel-preset-react-app'), 'linaria/babel'], + presets: [ + [ + require.resolve('babel-preset-react-app'), + { + runtime: 'automatic', + }, + ], + '@babel/preset-typescript', + '@linaria/babel-preset', + ], babelrc: false, configFile: false, }) diff --git a/src/index.js b/src/index.js index 3c9fedd..5d0f4f6 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,7 @@ module.exports = { } function overrideJestConfig({ jestConfig }) { - jestConfig.transform['^.+\\.(js|jsx|ts|tsx)$'] = require.resolve( + jestConfig.transform['^.+\\.(js|jsx|mjs|cjs|ts|tsx)$'] = require.resolve( './babelTransform.js', ) return jestConfig @@ -66,7 +66,9 @@ function transformBabelLoader(loader, pluginOptions) { const presets = options.presets || [] options.presets = presets const { babelOptions, ...linariaOptions } = - pluginOptions || (cosmiconfig('linaria').searchSync() || {}).config || {} + pluginOptions || + (cosmiconfig('@linaria/babel-preset').searchSync() || {}).config || + {} return { test: loader.test, @@ -76,11 +78,11 @@ function transformBabelLoader(loader, pluginOptions) { loader: loader.loader, options: { ...options, - presets: presets.concat('linaria/babel'), + presets: presets.concat('@linaria/babel-preset'), }, }, { - loader: 'linaria/loader', + loader: '@linaria/webpack-loader', options: { cacheDirectory: 'src/.linaria_cache', sourceMap: process.env.NODE_ENV !== 'production',