i have a tsc build react npm package.
And I want to use a png in my projekt.
Sadly i get an error when i try to build the projekt. Running Stroybook works fine. The Images also gets shown on the screen. Only when i try to build i reseive an error. So i think there is something wrong with the config. I Hope someone can help me fixing the config, so it will build successfully.
ERROR
npm run build
> [email protected] build
> tsdx build
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
✓ Creating entry file 1.2 secs
Error: Unexpected character '�' (Note that you need plugins to import files that are not JavaScript)
at D:2. repoportshare-frontend-libary-componentssrcimageplaceholder.png:1:0
1: ����►JFIF☺☺☺☺,☺,��VExifMM♦☺→♣☺>☺♣☺☺(♥☺☻☻‼♥☺☺☺,☺☺,☺��,Photoshop 3.08BIM♦♦∟☺Z♥��
�http://ns.adobe.com/xap/1.0/<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
^
2: <x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 10.10'>
3: <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
PS D:2. repoportshare-frontend-libary-components>
tsconfig
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"include": ["src", "types"],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
"importHelpers": true,
// output .d.ts declaration files for consumers
"declaration": true,
// output .js.map sourcemap files for consumers
"sourceMap": true,
// match output dir to input dir. e.g. dist/index instead of dist/src/index
"rootDir": "./src",
// stricter type-checking for stronger correctness. Recommended by TS
"strict": true,
// linter checks for common issues
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
// noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative
"noUnusedLocals": true,
"noUnusedParameters": true,
// use Node's module resolution algorithm, instead of the legacy TS one
"moduleResolution": "node",
// transpile JSX to React.createElement
"jsx": "react",
// interop between ESM and CJS modules. Recommended by TS
"esModuleInterop": true,
// significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS
"skipLibCheck": true,
// error out if import and file system have a casing mismatch. Recommended by TS
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
"resolveJsonModule": true, // Enable importing JSON files
"allowSyntheticDefaultImports": true, // Enable synthetic default imports
"allowUmdGlobalAccess": true, // Allow accessing UMD globals
"types": ["node"], // Include the 'node' type definitions
"target": "es2020",
"baseUrl": ".",
"paths": {
"*": ["types/*"],
"src/*": ["src/*"]
},
"downlevelIteration": true,
"typeRoots": ["node_modules/@types"]
}
}
tsdx.config.js
const scss = require('rollup-plugin-scss');
const { default: url } = require('@rollup/plugin-url');
module.exports = {
rollup(config, options) {
config.plugins.push(
scss({
output: true,
sass: require('sass'),
sassOptions: {
includePaths: ['src'],
},
watch: ['src'],
}),
url({
include: ['**/*.png'],
limit: 0,
fileName: '[name][extname]',
destDir: options.dir, // Use options.dir to determine the destination directory
})
);
return config;
},
};
globals.d.ts
declare module '*.png';
.babelrc.json
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": 100
}
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-optional-chaining",
"babel-plugin-inline-import"
]
}
package.json
{
"version": "0.1.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test --passWithNoTests",
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
"analyze": "size-limit --why",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"peerDependencies": {
"react": ">=16"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"name": "portshare-frontend-libary-components",
"author": "Leon Salenbacher",
"module": "dist/portshare-frontend-libary-components.esm.js",
"size-limit": [
{
"path": "dist/portshare-frontend-libary-components.cjs.production.min.js",
"limit": "10 KB"
},
{
"path": "dist/portshare-frontend-libary-components.esm.js",
"limit": "10 KB"
}
],
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/preset-env": "^7.22.5",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@rollup/plugin-url": "^8.0.1",
"@size-limit/preset-small-lib": "^8.2.4",
"@storybook/addon-essentials": "^7.0.21",
"@storybook/addon-interactions": "^7.0.21",
"@storybook/addon-links": "^7.0.21",
"@storybook/blocks": "^7.0.21",
"@storybook/react": "^7.0.21",
"@storybook/react-webpack5": "^7.0.21",
"@storybook/testing-library": "^0.0.14-next.2",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.5",
"babel-plugin-inline-import": "^3.0.0",
"file-loader": "^6.2.0",
"husky": "^8.0.3",
"node-sass": "^9.0.0",
"portshare-frontend-libary-objects": "^1.0.8",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.9.0",
"react-loading": "^2.0.3",
"react-router-dom": "^6.13.0",
"rollup-plugin-scss": "^4.0.0",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.63.6",
"sass-loader": "^13.3.2",
"size-limit": "^8.2.4",
"storybook": "^7.0.21",
"tsdx": "^0.14.1",
"tslib": "^2.5.3",
"url-loader": "^4.1.1"
},
"dependencies": {
"react-simple-star-rating": "^5.1.7",
"typescript": "^5.1.3"
}
}