-
Notifications
You must be signed in to change notification settings - Fork 12k
fix(webpack): fix css sourceMap option #3272
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf | |
const styles = appConfig.styles | ||
? appConfig.styles.map((style: string) => path.resolve(appRoot, style)) | ||
: []; | ||
const cssLoaders = ['css-loader?sourcemap&minimize', 'postcss-loader']; | ||
const cssLoaders = ['css-loader?sourceMap&minimize', 'postcss-loader']; | ||
return { | ||
output: { | ||
path: path.resolve(projectRoot, appConfig.outDir), | ||
|
@@ -37,15 +37,15 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf | |
}, { | ||
include: styles, | ||
test: /\.styl$/, | ||
loaders: ExtractTextPlugin.extract([...cssLoaders, 'stylus-loader?sourcemap']) | ||
loaders: ExtractTextPlugin.extract([...cssLoaders, 'stylus-loader?sourceMap']) | ||
}, { | ||
include: styles, | ||
test: /\.less$/, | ||
loaders: ExtractTextPlugin.extract([...cssLoaders, 'less-loader?sourcemap']) | ||
loaders: ExtractTextPlugin.extract([...cssLoaders, 'less-loader?sourceMap']) | ||
}, { | ||
include: styles, | ||
test: /\.scss$|\.sass$/, | ||
loaders: ExtractTextPlugin.extract([...cssLoaders, 'sass-loader?sourcemap']) | ||
loaders: ExtractTextPlugin.extract([...cssLoaders, 'sass-loader?sourceMap']) | ||
}, | ||
] | ||
}, | ||
|
@@ -71,7 +71,13 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf | |
options: { | ||
postcss: [ | ||
require('postcss-discard-comments') | ||
] | ||
], | ||
// workaround for https://github.com/webpack/css-loader/issues/340 | ||
context: path.resolve(__dirname, './'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment please |
||
// workaround for https://github.com/jtangelder/sass-loader/issues/298 | ||
output: { | ||
path: path.resolve(projectRoot, appConfig.outDir) | ||
} | ||
} | ||
}) | ||
] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you want to use
__dirname
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same value passed to context earlier in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hansl Solving this bug is quite important IMHO. Could you please take a closer look and propose an alternative if using
__dirname
is not acceptable?I've tried the fix and it and works fine (at last).
Thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative: project root.
The reason is the
__dirname
is the path to this file, but it might actually not be in the same directory than the project (for example, when younpm link
the CLI). I think the correct solution is to use the project root.Note that tutorial use
__dirname
because theirwebpack.config.js
are at the root of their project. So in their case it's the valid thing to do.Also,
path.resolve(__dirname, '.')
does nothing; just put the path in there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I have done is just a simple workaround for the fact that loader options plugin makes the original webpack config inaccessible to the other plugins. Probably the most correct way to apply the workaround would be to assign the entire webpack config to a var, so that the values can be re-used like this:
I did not do this simply because I wanted to keep the changes I make in this merge request as simple as possible. That's why I copied the exact config values from higher up in this same file. If you want those values changed I think it should be a separate merge request.
See L41 and L44