When my Node app includes the routes from my App I want to ignore non-js files e.g.
import './scss/App.scss' // i.e via Router.js -> Routes.js -> App.js
At the moment Node is obviously throwing a parse error as it's trying to parse the scss as js. The babel hook currently looks like this:
require('babel/register')({
stage: 0
});
Any ideas how I can make babel ignore them? Thanks
The purpose of babel is to transpile your js current code to an understandable version of js for the given environment, tool, framework you're using.
One of the ways you can use Babel is through the require hook. The require hook will bind itself to node's require and automatically compile files on the fly. This is equivalent to CoffeeScript's coffee-script/register.
Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.
The . babelrc file is your local configuration for your code in your project. Generally you would put it in the root of your application repo. It will affect all files that Babel processes that are in the same directory or in sibling directories of the . babelrc .
You can use babel-plugin-transform-import-ignore to ignore matched imports. All matched import statements will be removed after compilation.
{
plugins: [
[
"babel-plugin-transform-import-ignore",
{
patterns: [".scss"]
}
]
]
}
You can create .babelrc
file and set ignore
rule:
{
"stage": 0,
"ignore": [
"*.scss"
]
}
You can read more about this here - https://babeljs.io/docs/usage/babelrc/
Turns out it was node that needed the tweak:
require.extensions['.scss'] = () => {};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With