'RollupJS generate only index.js
I'm having some trouble with RollupJS.
I have one component library using typescript, react, AntDesign which using rollup.
Here my rollup 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 peerDepsExternal from 'rollup-plugin-peer-deps-external';
import url from 'rollup-plugin-url';
import postcssModules from 'postcss-modules';
import pkg from './package.json';
const cssExportMap = {};
export default {
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
},
{
file: pkg.module,
format: 'es',
exports: 'named',
sourcemap: true,
},
],
external: [
{
'react': 'react',
'react-dom': 'react-dom'
},
// Make antd library styles to be external to current project
/^antd[.]*/,
],
plugins: [
peerDepsExternal(),
url(),
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({
plugins: [
postcssModules({
getJSON (id, exportTokens) {
cssExportMap[id] = exportTokens;
}
})
],
getExportNamed: false,
getExport (id) {
return cssExportMap[id];
},
extract: 'build/styles.css',
use: ['sass', ['less', { javascriptEnabled: true, modifyVars: {
'hack': `true; @import "./public/theme/variables.module.less"`
}}]]
})
],
};
and my package.json has some scripts:
"build": "rollup -c",
"prepare": "yarn run build"
in local everything works fine and all the files are generated.
But when I'm using my library in a create-react-app application as dependency.
"ui-kit": "git+https://****:[email protected]/****/ui_kit_fe.git"
rollup generate only index.js inside build folder,
it should be: - style.css - index.es.js - index.js.map
but they are not there...
Solution 1:[1]
I've run into a similar problem myself. My build folder was present in the .gitignore
file, hence all its content except the main
entry point was excluded from installation . I've fixed this by adding the build folder into the files
array in package.json
:
"files": ["build/**/*"],
"main": "build/index.js",
You can find more info here: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrey Glotov |