diff --git a/packages/ripple-nuxt-ui/lib/module.js b/packages/ripple-nuxt-ui/lib/module.js index d3fb97893..f16f5b96c 100644 --- a/packages/ripple-nuxt-ui/lib/module.js +++ b/packages/ripple-nuxt-ui/lib/module.js @@ -1,10 +1,8 @@ const path = require('path') +const appDir = path.dirname(require.main.filename) const resolve = path.resolve -// TODO: this need to be updated after published to npm. -const nuxtNodeModulesPath = '../../../node_modules/' - module.exports = function nuxtRipple (moduleOptions) { const options = Object.assign({}, this.options.ripple, moduleOptions) @@ -17,19 +15,21 @@ module.exports = function nuxtRipple (moduleOptions) { this.extendBuild((config, { isServer }) => { // Exclude svg from url-loader - it conflicts with 'svg-sprite-loader'. + const rippleIconPath = path.dirname(require.resolve('@dpc-sdp/ripple-icon/package.json')) + const urlLoader = config.module.rules.find((rule) => rule.use && rule.use.find(r => r.loader === 'url-loader')) if (urlLoader) { urlLoader.exclude = [ - resolve(__dirname, nuxtNodeModulesPath + '@dpc-sdp/ripple-icon/'), - resolve(__dirname, '../../../assets/ripple-icon/') + resolve(__dirname, rippleIconPath), + resolve(__dirname, `${appDir}/assets/ripple-icon/`) ] } // Add svg-sprite-loader to create svg sprite config.module.rules.push({ test: /\.svg$/, include: [ - resolve(__dirname, nuxtNodeModulesPath + '@dpc-sdp/ripple-icon/'), - resolve(__dirname, '../../../assets/ripple-icon/') + resolve(__dirname, rippleIconPath), + resolve(__dirname, `${appDir}/assets/ripple-icon/`) ], use: [ 'svg-sprite-loader',