node.js - App bundles, but can't load assets from a node module at runtime -
i'm building application loading assets node_module. bundles fine, on runtime when navigate page, it's failing find webfonts used scss file i'm importing node module.
i see error in browser's javascript console:
bundle.js:129 uncaught error: cannot find module "../fonts/webfonts/salesforcesans-light.woff2"
the node module i'm importing scss structured so:
@salesforce-ux/design-system/ ├── assets │ ├── fonts │ │ └── webfonts │ │ └── [...all fonts...] │ ├── icons │ ├── images │ └── styles ├── scss │ ├── index.scss └── swatches
my webpack config:
var path = require('path'); var webpack = require('webpack'); module.exports = { entry: './src/myapp.js', output: { path: path.join(__dirname, '../public/dist'), filename: 'bundle.js' }, module: { preloaders: [ {test: /\.js$/, loader: 'eslint', exclude: /node_modules/} ], loaders: [ { test: /\.js$/, exclude: /node_modules/, loader: 'babel', query: { presets: ['es2015'] } }, { test: /\.scss$/, loaders: ['style', 'css?sourcemap','resolve-url','sass?sourcemap'], //the resolve-url loader important exclude: /node_modules/ }, { test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/, loader: 'url-loader?limit=100000' } ] } };
my app.js:
'use strict'; var express = require('express'); var path = require('path'); var app = express(); var port = process.env.port || 3000; app.set('views', './views'); app.set('view engine', 'html'); app.engine('html', require('ejs').renderfile); app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'node_modules/@salesforce-ux/design-system'))); app.get('/', function(req, res) { res.render('index.html'); }); app.listen(port, function() { console.log('listening on ' + port); });
my style sheet:
@import "~@salesforce-ux/design-system/scss/index.scss"; body { background: #eee; h1 { text-decoration: underline; } }
i'm sure i'm missing obvious, i'm new node , webpack, if there's additional code need see or insight, let me know.
Comments
Post a Comment