-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
Usage with untranspiled module in node_modules? #689
Comments
Managed to solve it. For future reference: Turns out
...where a majority of that code is copied right from |
@zth thank you!! |
@zth how did you get it to work on the client side in the first place? could you share your config? |
Ok, I figured it out. You need to extend the includes of the Here's a complete example config: 'use strict';
const nodeExternals = require('webpack-node-externals');
const fs = require('fs');
module.exports = {
modifyBabelOptions() {
return {
presets: ['razzle/babel'],
plugins: ['transform-flow-strip-types'],
};
},
modify(config, { target, dev }, webpack) {
// package un-transpiled packages
const babelRuleIndex = config.module.rules.findIndex(
(rule) => rule.use && rule.use[0].loader && rule.use[0].loader.includes('babel-loader')
);
config.module.rules[babelRuleIndex] = Object.assign(config.module.rules[babelRuleIndex], {
include: [
...config.module.rules[babelRuleIndex].include,
fs.realpathSync('./node_modules/untranspiled-package')
],
});
config.externals =
target === 'node'
? [
nodeExternals({
whitelist: [
dev ? 'webpack/hot/poll?300' : null,
/\.(eot|woff|woff2|ttf|otf)$/,
/\.(svg|png|jpg|jpeg|gif|ico)$/,
/\.(mp4|mp3|ogg|swf|webp)$/,
/\.(css|scss|sass|sss|less)$/,
/^untranspiled-package/,
].filter(Boolean),
}),
]
: [];
// return
return config;
},
}; |
I managed to do the same trick as @MrLoh also for Typescript ts-loader. Check allowedPackages, you can insert your package name there. I also took into account an idea that it seems that it is enough for current version of Razzle to be without custom config.externals, but you might be interested also in original @MrLoh solution (see about config.externals deletion: #842 (comment))
|
This worked with me. My question is, The libraries are being duplicated in the client and server bundle. Any way to chunk this common this into a new file using razzle.config.js ? |
Hi!
I'm trying to use a lib that ships untranspiled to NPM, and thus needs transpiling locally in the Razzle-project. I modified my razzle-config to include the module for transpilation in the js loader, and that seems to work fine for the client build as it no longer errors. However, I get the "unexpected token import"-error in what I assume is the server build.
Any ideas about this? I guess the problem is that I'd somehow need the module to be transpiled for the server as well?
Thanks in advance!
The text was updated successfully, but these errors were encountered: