123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- import resolve from "@rollup/plugin-node-resolve";
- import commonjs from "@rollup/plugin-commonjs";
- import image from '@rollup/plugin-image';
- import alias from '@rollup/plugin-alias';
- import postcss from 'rollup-plugin-postcss-modules'
- import babel from "rollup-plugin-babel";
- import { DEFAULT_EXTENSIONS } from '@babel/core';
- import json from "rollup-plugin-json";
- import autoprefixer from 'autoprefixer';
- import postcssUrl from 'postcss-url';
- import peerDepsExternal from 'rollup-plugin-peer-deps-external';
- import visualizer from 'rollup-plugin-visualizer';
- import analyze from 'rollup-plugin-analyzer';
- import ts from "@wessberg/rollup-plugin-ts";
- // import typescript from 'rollup-plugin-typescript2';
- // import sourcemaps from 'rollup-plugin-sourcemaps';
-
- // import url from '@rollup/plugin-url';
- // import less from "rollup-plugin-less";
- import nodeEval from 'node-eval';
-
- export function getModuleExports(moduleId) {
- const id = require.resolve(moduleId)
- const moduleOut = nodeEval(fs.readFileSync(id).toString(), id)
- let result = []
- const excludeExports = /^(default|__)/
- if (moduleOut && typeof moduleOut === 'object') {
- result = Object.keys(moduleOut)
- .filter(name => !excludeExports.test(name))
- }
- return result
- }
-
- export function getNamedExports(moduleIds) {
- const result = {}
- moduleIds.forEach( id => {
- result[id] = getModuleExports(id)
- })
- return result
- }
-
- const fs = require('fs');
- const path = require('path');
- const componentsFold = 'src/components';
- const cModuleNames = fs.readdirSync(path.resolve(componentsFold));
- const cModuleMap = cModuleNames.reduce((prev, name) => {
- const modulePath = `${componentsFold}/${name}`;
- prev[name] = `${modulePath}/index.ts`;
- const child = fs.readdirSync(path.resolve(modulePath));
- child.forEach(c => {
- const childFoldPath = `${modulePath}/${c}`;
- const isDir = fs.statSync(childFoldPath).isDirectory();
- if (isDir) {
- if (fs.existsSync(`${childFoldPath}/index.tsx`)) {
- prev[c] = `${childFoldPath}/index.tsx`;
- }
- if (c === 'Common' && fs.existsSync(childFoldPath) && fs.statSync(childFoldPath).isDirectory()) {
- const commonComponentsArr = fs.readdirSync(childFoldPath);
- commonComponentsArr.forEach(commonComponentFold => {
- const commonComponentFoldPath = `${childFoldPath}/${commonComponentFold}`;
- const isCommonComponentDir = fs.statSync(commonComponentFoldPath).isDirectory();
- if (isCommonComponentDir && fs.existsSync(`${commonComponentFoldPath}/index.tsx`)) {
- prev[`${commonComponentFold}`] = `${commonComponentFoldPath}/index.tsx`;
- }
- });
- }
- }
- });
- return prev;
- }, {});
-
- const extensions = [ ...DEFAULT_EXTENSIONS, '.js', '.jsx', '.ts', '.tsx'];
-
- export default {
- input: {
- '.': "src/lib-build.ts",
- ...cModuleMap
- },
- output: [
- {
- dir: "lib",
- sourcemap: true,
- entryFileNames: '[name]/index.js',
- exports: 'named',
- // file: "lib/bundle.js",
- format: "cjs"
- },
- {
- dir: "eslib",
- sourcemap: true,
- entryFileNames: '[name]/index.js',
- exports: 'named',
- // file: "lib/bundle.js",
- format: "es"
- }
- ],
- plugins: [
- peerDepsExternal(),
- resolve({
- mainFields: ['jsnext'],
- preferBuiltins: true,
- browser: true,
- extensions,
- }),
- image(),
- json(),
- // sourcemaps(),
- commonjs({
- include: /node_modules/,
- browser: true,
- namedExports: {
- ...getNamedExports([
- 'prop-types',
- 'draft-js',
- ]),
- 'braft-extensions/dist/emoticon': ['defaultEmoticons']
- },
- }),
- // url(),
- // less(),
- postcss({
- extensions: ['.css', '.less'],
- plugins: [
- autoprefixer(),
- postcssUrl({
- url: 'inline'
- }),
- ],
- modules: true,
- }),
- ts({
- exclude: "node_modules/**",
- transpiler: "babel",
- hook: {
- outputPath: (path, kind) => {
- return path
- }
- }
- }),
- // typescript({
- // include: ["*.js+(|x)", "**/*.js+(|x)", "*.ts+(|x)", "**/*.ts+(|x)"],
- // verbosity: 3,
- // clean: true,
- // typescript: require('typescript'),
- // // useTsconfigDeclarationDir: true,
- // rollupCommonJSResolveHack: true,
- // objectHashIgnoreUnknownHack: true,
- // }),
- babel({
- exclude: "node_modules/**",
- runtimeHelpers: true,
- extensions,
- }),
- alias({
- entries: [
- { find: '@', replacement: 'src' },
- { find: '@components', replacement: 'src/components' },
- ],
- }),
- visualizer({
- sourcemap: true,
- open: true,
- }),
- analyze(),
- ],
- onwarn: function(warning) {
- // Skip certain warnings
- // should intercept ... but doesn't in some rollup versions
- if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }
- // console.warn everything else
- console.warn( warning.message );
- }
- };
|