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

feat: Enable importing CSS from node_modules #9543

Merged
merged 21 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions flow-server/src/main/resources/webpack.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,10 @@ module.exports = {
loader: 'css-loader',
options: {
url: (url, resourcePath) => {
// Skip translating external URLs
const extUrlPattern = /(http|https):\/\//;
if (extUrlPattern.test(url)) {
return false;
}
// Only translate files from node_modules or frontend/theme
return resourcePath.includes('/node_modules/')
|| resourcePath.includes('/frontend/theme/');
// Only translate files from node_modules
const resolve = resourcePath.match(/(\\|\/)node_modules\1/);
const themeResource = resourcePath.match(themePartRegex) && url.match(/^theme\/[\s\S]*?\//);
return resolve || themeResource;
},
// use theme-loader to also handle any imports in css files
importLoaders: 1
Expand All @@ -205,13 +201,19 @@ module.exports = {
],
},
{
// File-loader only copies files used as imports in .js files
test: /\.(png|gif|jpg|svg|eot|woff|woff2|ttf)$/,
// File-loader only copies files used as imports in .js files or handled by css-loader
test: /\.(png|gif|jpg|jpeg|svg|eot|woff|woff2|ttf)$/,
use: [{
loader: 'file-loader',
options: {
outputPath: 'static/',
name: '[name].[ext]'
name(resourcePath, resourceQuery) {
const urlResource = resourcePath.substring(frontendFolder.length);
if(urlResource.match(themePartRegex)){
return /^(\\|\/)theme\1[\s\S]*?\1(.*)/.exec(urlResource)[2];
}
return '[path][name].[ext]';
}
}
}],
},
Expand Down
2 changes: 1 addition & 1 deletion flow-tests/test-themes/frontend/theme/app-theme/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body {

#butterfly {
/* This shouldn't be translated */
background-image: url("./test/path/monarch-butterfly.jpg");
background-image: url("/path/test/path/monarch-butterfly.jpg");
caalador marked this conversation as resolved.
Show resolved Hide resolved
width: 300px;
height: 274px;
display: block;
Expand Down