Conditional compilation in rollup - rollup

How can I exclude some part of code in file (not the file itself but only few lines) from compiling into bundle? In C# it looks like
#ifdef _DEBUG
...
#else
...
#endif
Is it possible for js files compiling with rollup?

rollup-plugin-jscc
Possibly you need rollup-plugin-jscc, but I'm not sure about it's state in 2022 :(
In usage section of linked README.md file you can find example:
/*#if _DEBUG
import mylib from 'mylib-debug';
//#else */
import mylib from 'mylib'
//#endif
mylib.log('Starting $_APPNAME v$_VERSION...')
#rollup/plugin-alias
Another solution is a little bit different:
/*START.DEBUG_ONLY*/
import 'robot3/debug';
/*END.DEBUG_ONLY*/
import {...} from 'robot3';
Also you can use official #rollup/plugin-alias to mock import 'robot3/debug', but this approach needs empty mock-file for replacement, what is not so clean.
rollup.config.js
import alias from '#rollup/plugin-alias';
module.exports = {
input: ...,
output: ...,
plugins: [
...,
alias({
entries: [
{ find: 'robot3/debug', replacement: resolve(__dirname, './src/mocks/empty.js') },
]
})
]
};

Related

Shorter Way for URLs with vscode on react native

So I have a react native project, and in that project many of my urls start looking like this: import Component from '../../component/file';
So after this problem I saw this video by fireshipio with says I can shorten it by adding a jscofig.json file but it did not work when I wrote import Component from '../../component/file';
it just told me it could not find the path please tell me what I am supposed to do to make this working because if its possible my links will become so much shorter and smarter. Remember the programming rule do not repeat yourself so please help me follow that.
link to fireshipio vid: https://www.youtube.com/watch?v=WpgZKBtW_t8
You should Modify/Add your desired common path in babel.config.js file and then you can easily import any file/class without adding long paths
Here is an example of babel.config.js from one of my project.
module.exports = api => {
api.cache(true);
return {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'#babel/plugin-proposal-optional-chaining',
'#babel/plugin-proposal-nullish-coalescing-operator',
[
'module-resolver',
{
root: ['./src'],
alias: {
'#routes': ['./src/routes.js'],
'#navigations': ['./src/navigations'],
'#components': ['./src/components'],
'#store': ['./src/store'],
'#images': ['./src/images'], //You can add your source path like this
'#utils': ['./src/utils'],
},
},
],
],
};
};
After adding the source path in babel.config.js you can import the files like this in your class.
import SampleImage from '#images/sampleImage.png'
You can import like this in your any class, No need to do '../../src/image/sampleImage.png'

How to import whole SCSS folder in Vue Nuxt project?

At my company we are not writing css in Vue files, we prefer to do it the old way with SCSS.
Problem is, we end up with a need of writing new import in styles.scss any time we create new component, and it really bugs me in bigger projects.
Not so long ago, when I have been developing in React, I imported module called node-sass-glob-importer in webpack.config file, tweaked a bit (you can check here) and it worked - I could have imported folder like this: #import "components/**";
In Nuxt, I only have nuxt.config.js file and I am lost a bit. I know how to extend some simple stuff there, but this seems to be more complicated.
Any help of importing node-sass-glob-importer or doing the same thing in some other way?
how about using https://github.com/nuxt-community/style-resources-module and than:
export default {
modules: ['#nuxtjs/style-resources'],
styleResources: {
scss: [
'./assets/yourFolder/*.scss'
]
}
}
You can use node-sass-glob-importer in Nuxt like this:
nuxt.config.js:
const globImporter = require('node-sass-glob-importer');
export default {
...
css: [
'~/assets/scss/global.scss'
],
...
build: {
extend(config, {loaders: {scss}}) {
const sassOptions = scss.sassOptions || {};
sassOptions.importer = globImporter();
scss.sassOptions = sassOptions;
}
}
}
global.scss:
#import "./assets/scss/base/*";
#import "./assets/scss/components/*";
styleResources is used for things like variables, mixins and functions that you want to use anywhere in your SCSS without having to import the files.

How to import index.vue by just mentioning the parent directory name rather than filename?

I've been building my Vue application by using Vue Cli 3.
If I need to import an index.js which is in directory named Dir1, I can import it using
import file1 from '#/components/Dir1/
but somehow it doesn't work with .vue extension files.
I have to expicitly mention the file name such as import Title from #/components/Title/index.vue.
What changes do I have to make in the settings in order to import the .vue extension file without mentioning the filename?
This is how I would do it with Vue.
You may need to tweak the config a little bit to suit your dev environment needs.
Note that this is not a full config but a guideline on what should be done based on NPM directory-named-webpack-plugin documentation.
In your webpack.config.js you should have the following (Webpack 3):
const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin');
// ...
let config = {
// ...
module: {
rules: [
{
test: /\.(js|vue)$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
},
resolve: {
modules: ['components', 'node_modules'],
extensions: ['.js', '.vue'],
plugins: [
new DirectoryNamedWebpackPlugin(true)
]
}
// ...
}
modules.exports = config;
taken and modified for Vue from: Recursive import of components using webpack in React

Compile scss with #import and $variables to rollupjs

I'm compiling my first angular library using rollupjs and I need your help :)
Currently I have a structure like this:
.src
--components
--component1
--component1.ts
--component1.scss
--component1.html
--common
--_variables.scss
And my component1.scss looks like this
#import "../../core/sass/variables";
:host {
.trigger {
&.clear_btn {
color: $color-grey;
}
}
}
My variables.sccs looks like:
$color-grey-light: #e3e3e3;
$color-grey: #bfbfbf;
and my rollup.config.js looks like:
export default {
input: 'build/index.js',
output: {
file: 'dist/common.js',
format: 'es',
},
plugins: [
angular({
preprocessors: {
template: template => minifyHtml(template, htmlminOpts),
style: scss => {
const css = sass.renderSync({data: scss}).css;
return cssmin.minify(css).styles;
},
}
})
],
external: [
'#angular/core',
'#angular/animations',
'#angular/router',
'#angular/platform-browser',
'#angular/forms'
]
};
but when I execute I get this error:
[!] (angular plugin) Error: File to import not found or unreadable: ../../core/sass/variables.
Parent style sheet: stdin
build/app/components/toggle/toggle.component.js
Error: File to import not found or unreadable: ../../core/sass/variables.
Parent style sheet: stdin...
I tried adding importer from node-sass but to be honest I have no idea how to use it to compile everything into css and then inject it to my js (I can actually inject the scss into my template by using rollup-plugin-angular but I don't know how to compile scss)
Any help, tips or suggestions will be really appreciated :)

Using and deriving from interfaces defined in another COM library

I have two C++ COM projects in Visual Studio. In ProjectA I define InterfaceA in MIDL. In ProjectB I would like to define InterfaceB which inherits from InterfaceA. Is this possible to do without importing IDL or H files from ProjectA?
Here's how the code is laid out, which might be clearer. The libraries are large so I put things in separate files to make it easier to maintain.
Project A
InterfaceA.idl
import "oaidl.idl";
import "ocidl.idl";
[ uuid( ... ) ]
interface InterfaceA : IDispatch { ... }
CoclassA.idl
import "InterfaceA.idl";
[ uuid( ... ) ]
interface CoclassA
{
[default] interface InterfaceA;
};
ProjectA.idl
import "InterfaceA.idl";
[ uuid( ... ) ]
library ProjectA
{
interface InterfaceA;
#include "CoclassA.idl"
}
Project B
InterfaceB.idl
import "oaidl.idl";
import "ocidl.idl";
// If both interfaces were in the same project, I'd just import:
//import "InterfaceA.idl";
// Without the import I get a compilation error, obviously. I don't want to
// add ProjectA as an additional include directory because I don't want ProjectB
// to be dependent on how ProjectA's files are organized. I just want the types
// from ProjectA to be available here.
[ uuid(...) ]
interface InterfaceB: InterfaceA { ... }
CoclassB.idl
import "InterfaceB.idl";
[ uuid( ... ) ]
interface CoclassB
{
[default] interface InterfaceB;
};
ProjectB.idl
import "InterfaceB.idl";
[ uuid( ... ) ]
library ProjectB
{
// I wish using importlib would help here, but it won't since InterfaceB is
// defined and compiled by MIDL separately in InterfaceB.idl.
//importlib("ProjectA.tlb");
// I could try to #include "InterfaceB.idl", but then I would lose the
// automatic dependency analysis that MIDL does. I am also having trouble
// getting the MIDL compiler to understand #defines.
interface InterfaceB;
#include "CoclassB.idl"
}
I have a feeling that what I want to do is not possible. This wouldn't be a problem if MIDL supported an importlib equivalent outside of libraries!