Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby-plugin-theme-ui, add path option #1355

Closed
fcisio opened this issue Dec 10, 2020 · 8 comments · Fixed by #1359
Closed

gatsby-plugin-theme-ui, add path option #1355

fcisio opened this issue Dec 10, 2020 · 8 comments · Fixed by #1359
Assignees

Comments

@fcisio
Copy link
Collaborator

fcisio commented Dec 10, 2020

Is your feature request related to a problem? Please describe.
Not a problem, but it would be nice to be able to specify the theme path with an option.

The default path is src/gatsby-plugin-theme-ui/index.js

Describe the solution you'd like
Something like:

{
    resolve: 'gatsby-plugin-theme-ui',
    options: {
        path: 'src/theme/index.js'
    },
},
@atanasster
Copy link
Collaborator

@fcisio yes, great suggestion. I believe it can be lumped with the theme “shadowing” in src/theme.{js,json,ts} as listed in the v1 roadmap : #832 or just replace it.

Would you like to submit a PR, or i can also assign it to myself?

@fcisio
Copy link
Collaborator Author

fcisio commented Dec 11, 2020

Thanks @atanasster
That's a bit out of my reach for now, unfortunately.

But starting next year, I will be using Theme UI more intensively and should be able to bring more people to help on this project 🎉

@atanasster
Copy link
Collaborator

wow, thats great hear, what kind of projects are you doing with theme-ui?

I will file a PR on this one - since you are finding a lot of great bugs and new features - just let me know anytime you prefer to file a PR yoursel

@atanasster atanasster self-assigned this Dec 12, 2020
@atanasster
Copy link
Collaborator

Hi @fcisio I looked a bit closer and remembered that you can actually pass the theme object as an option to the plugin - you just need to require the theme from wherever it is located:

in gatsby-config.js :

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-theme-ui',
      options: {
        preset: require('./src/theme'),
      },
    },
  ],
}

Since gatsby-config does not support es6 modules you will need to module.export the theme

module.exports = {
  colors: {
    text: '#000',
    background: '#fff',
    primary: 'green',
    secondary: '#609',
  },

Would this work for you?

@lachlanjc
Copy link
Member

Oh amazing @atanasster. Maybe we should add an example like that to https://theme-ui.com/packages/gatsby-plugin?

@atanasster
Copy link
Collaborator

Thanks @lachlanjc - I sent a PR, can you please check the text : https://theme-ui-gr3r68aaa.vercel.app/packages/gatsby-plugin

@hasparus
Copy link
Member

Since gatsby-config does not support es6 modules

You could also use babel-register or ts-node.

const sourceMapSupport = require("source-map-support");
const tsNode = require("ts-node");

let registered = false;

module.exports = function registerTsNode() {
  if (registered) {
    return;
  }

  registered = true;

  sourceMapSupport.install();
  tsNode.register({
    compilerOptions: {
      module: "commonjs",
      target: "es2017",
      // TS_NODE_FILES is set to false, so declarations.d.ts are not loaded
      noImplicitAny: false,
      project: "../../../tsconfig.json",
    },
  });
};

module.exports = require("./gatsby-config.ts");

https://github.com/hasparus/homepage/blob/master/gatsby-config.js

@lachlanjc lachlanjc linked a pull request Dec 14, 2020 that will close this issue
@atanasster
Copy link
Collaborator

atanasster commented Dec 16, 2020

You could also use babel-register or ts-node.

Yeah, couple of workarounds.
I am compiling a gatsby-config.ts(all the gatsby config type files) from src and then pointing to dist https://github.com/ccontrols/component-controls/blob/master/integrations/gatsby-theme-stories/gatsby-config.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants