Накопительный пакет не внедряет мою тему в библиотеку компонентов, используя AntDesign в качестве PeerDependencie - PullRequest
0 голосов
/ 25 марта 2020

У меня возникли некоторые проблемы с настройкой накопительного пакета, я создаю библиотеку компонентов, которая имеет PeerDependencies: Ant Design and React Я пытаюсь внедрить пользовательскую тему с помощью подключаемого модуля Less с помощью параметра Less modifyVar.

У меня такой же конфиг с storyBook с использованием webpack.config, и вот он работает ...

здесь мой накопительный конфиг:

import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import typescript from 'rollup-plugin-typescript2';
import { uglify } from "rollup-plugin-uglify";
import minify from 'rollup-plugin-babel-minify';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';

const path = require('path');
const fs  = require('fs');
const lessToJs = require('less-vars-to-js');
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, './src/theme/variables.module.less'), 'utf8'), {resolveVariables: true, stripPrefix: true});


export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/index.js',
    format: 'cjs'
  },
  external: [
    {
      'react': 'react',
      'react-dom': 'react-dom',
      'classnames': 'classnames'
    },
    // Make antd library styles to be external to current project
    /^antd[.]*/,
  ],
  plugins: [
    peerDepsExternal(),
    uglify(),
    minify( {
      // Options for babel-minify.
    } ),
    typescript({
      exclude: ['*.d.ts', '**/*.d.ts', '**/*.stories.tsx', '**/*.spec.tsx'],
      rollupCommonJSResolveHack: true,
      clean: true,
    }),
    babel({
      babelrc: false,
      plugins: [['import', { libraryName: 'antd', style: true }]],
      extensions: ['.js', '.jsx', '.ts', '.tsx'],
      exclude: 'node_modules/**',
    }),
    commonjs({
      include: 'node_modules/**'
    }),
    postcss({
      use: [['less', {javascriptEnabled: true, modifyVars: themeVariables}]
    ]
    })
  ],
};

здесь мой Конфигурация сборника рассказов

// you can use this file to add your custom webpack plugins, loaders and anything you like.
// This is just the basic way to add additional webpack configurations.
// For more information refer the docs: https://storybook.js.org/configurations/custom-webpack-config

// IMPORTANT
// When you add this file, we won't add the default configurations which is similar
// to "React Create App". This only has babel loader to load JavaScript.

const path = require('path');
const fs  = require('fs');
const SRC_PATH = path.join(__dirname, '../src')

const lessToJs = require('less-vars-to-js');
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, '../src/theme/variables.module.less'), 'utf8'), {resolveVariables: true, stripPrefix: true});

module.exports = {
  plugins: [],
  resolve: {
    extensions: ['.ts', '.tsx', '.less']
  },
  module: {
    rules: [
      // add your custom rules.
      {
        loader: 'babel-loader',
        exclude: /node_modules/,
        test: /\.(ts|tsx|js|jsx)$/,
        options: {
          presets: ['@babel/react'],
          plugins: [
              ['import', {
                libraryName: 'antd',
                libraryDirectory: 'es',
                style: true
              }]
          ]
        },
      },
      {
        test: /\.(ts|tsx)$/,
        include: [SRC_PATH],
        use: [
          {
            loader: require.resolve('awesome-typescript-loader'),
            options: {
              configFileName: './tsconfig.json'
            }
          }
        ]
      },
      {
        test: /\.less$/,
        use: [
          { loader: "style-loader" },
          { loader: "css-loader", options: {
            modules: 'global'
          } },
          { loader: "less-loader",
          options: {
            modifyVars: themeVariables,
            javascriptEnabled: true
          },
        }
        ],
        include: [
          path.resolve(__dirname, '../src'),
          /[\\/]node_modules[\\/].*antd/
        ]
      },
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ],
  },
};

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...