Skip to content

Installing dependencies (like node-sass) in a custom theme  #353

Closed
@whoan

Description

@whoan

I'm creating a custom theme for my blog and I don't find a way to avoid modifying the vuepress project itself, to make the theme build properly.

I am currently having problems with the following dependencies:

node-sass
sass-loader

If I add them to vuepress itself it works fine but I have the idea to make the repo public, so I wish the repo was easy to install.

I tested modifying the file lib/webpack/createBaseConfig.js (with partial success) adding this line:

diff --git a/lib/webpack/createBaseConfig.js b/lib/webpack/createBaseConfig.js
index f2a6ec8..cd3c012 100644
--- a/lib/webpack/createBaseConfig.js
+++ b/lib/webpack/createBaseConfig.js
@@ -60,6 +60,7 @@ module.exports = function createBaseConfig ({
     .set('symlinks', true)
     .modules
       // prioritize our own
+      .add(path.resolve(__dirname, themePath + '/node_modules'))
       .add(path.resolve(__dirname, '../../node_modules'))
       .add(path.resolve(__dirname, '../../../'))
       .add('node_modules')

...it worked adding my custom theme to the vuepress project (in the folder docs/.vuepress/) but it didn't work with the vuepress cli (ie: vuepress dev failed).
If it worked, I was thinking in make a PR to add that line to the vuepress repo but it seems it is not enough.

What is the correct way to handle this kind of dependencies in a custom theme?
Notice it's easier with other kind of assets (eg: bootstrap) and I could hanlde them creating a package.json in the custom theme and using the proper paths in my code.


This is my environment but I think it's not relevant in this case:

  • Arch Linux 4.16.6-1
  • Node.js 9.11.1
  • VuePress 0.8.4
  • Firefox 59.02
  • Global install
  • I use yarn

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions