Add webpack aliases for Crayons components (#6958)

* Added webpack alias for @crayons.

* Added @crayons to eslint import/no-unresolved rule ignore list.

* Added path mappings for VS Code for webpack aliases.
This commit is contained in:
Nick Taylor 2020-03-31 07:16:29 -04:00 committed by GitHub
parent 40310bbc59
commit 5ba10c96a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View file

@ -32,6 +32,12 @@ module.exports = {
},
],
'react/jsx-no-target-blank': [2, { enforceDynamicLinks: 'always' }],
'import/no-unresolved': [
'error',
{
ignore: ['@crayons'],
},
],
},
globals: {
getCsrfToken: false,

View file

@ -33,6 +33,7 @@ module.exports = {
...config.resolve.alias,
react: 'preact-compat',
'react-dom': 'preact-compat',
'@crayons': path.resolve(__dirname, '../crayons'),
},
};

View file

@ -1,4 +1,5 @@
/* global require module */
const path = require('path');
const { environment } = require('@rails/webpacker');
const erb = require('./loaders/erb');
@ -10,9 +11,19 @@ the existing configuration and only override/add what is necessary.
The cache groups section is the default cache groups in webpack 4. See https://webpack.js.org/plugins/split-chunks-plugin/#optimizationsplitchunks.
It does not appear to be the default with webpacker 4.
*/
environment.splitChunks(config => {
environment.splitChunks((config) => {
return {
...config,
resolve: {
...config.resolve,
alias: {
...(config.resolve ? config.resolve.alias : {}),
'@crayons': path.resolve(
__dirname,
'../../app/javascript/crayons',
) /* global __dirname */,
},
},
optimization: {
...config.optimization,
splitChunks: {

9
jsconfig.json Normal file
View file

@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@crayons/*": ["app/javascript/crayons/*"]
}
},
"exclude": ["node_modules", "**/node_modules/*"]
}