-
Notifications
You must be signed in to change notification settings - Fork 213
Provide example for resolving module paths to source dir (FAQ?) #747
Comments
I'm actually trying to do this myself right now, and I can't get this to work: module.exports = {
options : {
mains : {
index : "index",
index2: "index2",
},
},
use : [
[
'@neutrinojs/react',
(neutrino) => neutrino.config.resolve.modules.add(neutrino.options.source),
{
html : {
title : "Test App"
}
},
]
]
}; As best as I can tell, passing a middleware after the Similarly, if I add logging and a There's gotta be something obvious here that I'm missing, but I don't know what. |
I'm already write this problem on the spectrum.chat module.exports = {
use: [
[
'@neutrinojs/react',
{
html: {
title: 'njs-react-no-lint'
}
},
],
(neutrino) => {
neutrino.config.resolve
.modules
.add(neutrino.options.source),
},
],
}; The root 'src' is resolved, and i can use import of my components like this: import React from 'react';
import Button from 'components/Button'; // --- resolved by webpack ---
import './App.css';
const App = () => (
<div className="App">
<h1>{'Neutrino with eslint configured without middleware only => .eslintrc.js'}</h1>
<Button>Button</Button>
</div>
);
export default App; Real issue comming if i try to make working airbnb eslint rules with: 'eslint-plugin-import' package. I can't make it working the way 'elint-plugin-import' will stop to complain about lint error like on screenshot bellow. Here is my .neutrionorc.js configuration where i'm trying to resolve the issue with eslint: const { resolve } = require('path');
const { merge } = require('@neutrinojs/compile-loader');
module.exports = {
use: [
[
'@neutrinojs/react',
{
html: {
title: 'njs-react-no-lint'
}
},
],
(neutrino) => {
neutrino.config.resolve
.modules
.add(neutrino.options.source),
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => merge({
plugins: [
[
require.resolve('babel-plugin-root-import'),
{
rootPathPrefix: '@',
rootPathSuffix: 'src',
}
],
]
}, options));
},
],
}; I'm use So for now my solution is to disallow this two linting rules in my eslint configuration. |
@markerikson I think you have some problems with your middleware formatting (if I'm understanding correctly). Can you try it like this:
|
..... Oh. Y'know what? I think I see what you're getting at. The array brackets may be off-by-one-ish there, so I'm accidentally putting the middleware inside the |
@markerikson yep. I tend to find the array middleware format a little hard to read for that reason. All preferences, but I would probably avoid it like so:
|
Yeah, that was it. Boy, do I feel silly :) Thanks! |
Also I'm think my case with resolving modules for eslint is related to this issue: #708 This is maybe also not right place for issue in my case sorry for that, but i can suggest to write about how to configure |
@YuriiF I'll try and use you config to debug today. |
@timkelty Great thanks here is two gist's with neutrino configuration and package.json that i'm tried hope it will help: https://gist.github.com/YuriiF/6c1274aa86bb3aef49b32b2a11732098 I'm tried two resolvers for eslint:
|
I was having the same problem, i debugged neutrino with:
Eslint somehow gets an eslint config with some of our configs overridden when neutrino sets I added |
Oooo, that's a good point. I wonder if we should revise the |
That could be problematic if the user doesn't actually have an |
The |
That makes sense :) |
Not working on Jest:// .neutrinorc.js
const standard = require('@neutrinojs/standardjs');
const node = require('@neutrinojs/node');
const jest = require('@neutrinojs/jest');
module.exports = {
options: {
root: __dirname,
tests: 'src',
},
use: [
standard(),
node(),
jest(),
neutrino => {
neutrino.config.resolve.alias.set('local', neutrino.options.source);
},
],
}; // jest.config.js
const neutrino = require('neutrino');
const path = require('path');
process.env.NODE_ENV = process.env.NODE_ENV || 'test';
const config = neutrino().jest();
console.log(config);
module.exports = config; Console output{ rootDir: '/project-folder',
moduleDirectories: [ 'node_modules' ],
moduleFileExtensions: [ 'wasm', 'jsx', 'js', 'json' ],
moduleNameMapper:
{ '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'/project-folder/node_modules/@neutrinojs/jest/src/file-mock.js',
'\\.(css|less|sass|scss)$':
'/project-folder/node_modules/@neutrinojs/jest/src/style-mock.js',
'^local$':
'/project-folder/src$1' },
bail: true,
collectCoverageFrom: [ 'src/**/*.{mjs,jsx,js}' ],
testEnvironment: 'node',
testRegex: 'src/.*(_test|_spec|\\.test|\\.spec)\\.(mjs|jsx|js)$',
verbose: false,
transform:
{ '\\.(mjs|jsx|js)$':
'/project-folder/node_modules/@neutrinojs/jest/src/transformer.js' } } Temporary solution// jest.config.js
const neutrino = require('neutrino');
const path = require('path');
process.env.NODE_ENV = process.env.NODE_ENV || 'test';
const config = neutrino().jest();
delete config.moduleNameMapper['^local$']
config.moduleNameMapper['^local/(.*)$'] = path.join(__dirname, 'src/$1')
module.exports = config; |
It seems common that people want to add a module resolving path to their source path.
The easiest way to do this is:
Or if an alias is preferred:
The text was updated successfully, but these errors were encountered: