-
-
Notifications
You must be signed in to change notification settings - Fork 384
feat: emitFile option #722
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: emitFile option #722
Conversation
Add emitFile option (default: true). * If true, emits a file (writes a file to the filesystem). * If false, the plugin will extract the CSS but will not emit the file. It is often useful to disable this option for server-side packages.
Why you need this plugin for SSR? |
It is explained in the PR. Without the plugin the resulting ssr |
Sorry, again, just ignore CSS |
That is also explained in the PR provided usecase and also not possible. The css is not "required" or "imported" but extracted from the .vue single file component by vue-loader and passed to this plugin for extraction. |
In this case you need to open an issue in |
Vue loader delegates css extraction (see https://vue-loader.vuejs.org/guide/extract-css.html#webpack-4) to this plugin. Extracting css is the main and only reason this plugin exists. file-loader, the equivalent for the other file types implements it already. If there is no technical reason not to: why the resistance to implement it? |
Because we don't need this option:
|
Also implementation is invalid, because we don't need process something in loader, we can just return empty content |
Because they would just sink the files using
#74, nearing 3 years now and that had other parties interested, not just myself.
It does make sense. If you don't extract the CSS it remains in the .js file. It makes index.js (in this example) a 2.7M files instead of a 1.6M.
This is not a technical issue. The new option is optional and does not change the default behavior, be it for cache or otherwise. A warning in the doc saying |
Can you provide link on docs or examples?
This issue from you
But you can just ignore all
We don't want to provide unsafe options |
Even after I closed it other person asked to reopen because of a similar need.
Here is the same option on
They implemented this in 2016 (webpack-contrib/file-loader@20c8fff), it is useful.
How? |
I mean for SSR and CSS, no need to link on |
There is no difference. SSR and CSS (in this plugin) or SSR and a PNG (for file-loader) are the same case. It just wastes space in the javascript or disk |
You are correct that the option is not really required to be in this plugin, one can just use const webpack = require('webpack');
const path = require('path');
const { VueLoaderPlugin } = require('vue-loader');
// const MiniCssExtractPlugin = require('../../../dist/cjs.js');
module.exports = {
mode: 'development',
target: 'node',
output: {
path: path.join(__dirname, '..', '..', 'dist', 'current-plugin', 'ssr'),
publicPath: '/assets'
},
entry: {
index: './src/index.js',
},
module: {
rules: [
{
test: /\.vue$/,
use: 'vue-loader'
},
{
test: /\.css$/,
use: [
{ loader: "vue-style-loader" },
{ loader: "null-loader" }, // <------------- add this instead
// { loader: MiniCssExtractPlugin.loader, options: { esModule: false } },
// { loader: "css-loader" }
]
}
]
},
plugins: [
new webpack.DefinePlugin({
COMPILE_TARGET: JSON.stringify('node')
}),
new VueLoaderPlugin(),
// new MiniCssExtractPlugin({
// filename: '[name].css'
// })
],
devtool: false
} It would be nice to have it tho, meaning the same plugin / loader could be used in either case with a single option being the difference.
Can you elaborate? |
@alexander-akait : from what I understand your suggestion would be
That would be it? |
Closing the PR because from what I've understood it is not implemented correctly and doesn't merit further discussion. Also opened webpack/webpack#12920 because, with |
You don't need |
@alexander-akait : Is it possible to do that without knowing at configuration time the name of the files to be ignored? Documentation says you have to ignore by name using resolve.alias |
webpack/webpack#12920 is not solve your problem, CSS modules will not work |
Let's reopen, after investigate I found what locals can be broken with |
Reopened and it works and passes all tests. All that's missing
right? |
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.
Let's move it on loader
level, need just avoid https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/loader.js#L193 and https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/loader.js#L157 when emit false and let's rename option to emit
Renamed from emitFile
Codecov Report
@@ Coverage Diff @@
## master #722 +/- ##
===========================================
- Coverage 89.67% 70.39% -19.28%
===========================================
Files 6 6
Lines 775 777 +2
Branches 239 241 +2
===========================================
- Hits 695 547 -148
- Misses 77 212 +135
- Partials 3 18 +15
Continue to review full report at Codecov.
|
Done. Will move the logic from the plugin to the loader as requested |
@alexander-akait : done, it works. You can check with
The only difference in the config is It also does not erase |
Removed the unnecessary check. Codecov was complaining about it and there is only one caller for this function a few lines below, dependencies is guaranteed to be an array
@alexander-akait : before reviewing, let me create an usecase for |
Keep addDependencies to ensure watch works
Restoring mistakenly removed formatting
@alexander-akait : done! To test all usecases and the new one for locals:
Compilation result will be at Then to test the version with locals
The result must be { a: 'foo__style__a', b: 'foo__style__b' } Which is the same result from the example this was copied from: https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/test/cases/commonjs-module-syntax/webpack.config.js Please review and validate. |
@alexander-akait , @cap-Bernardito : I assume #732 is a more elegant way to implement this, thanks for merging. |
This PR contains a:
Motivation / Use-Case
Add emit option (default: true).
The use case for this this option is the same of the already existing on
file-loader
(see https://github.com/webpack-contrib/file-loader#emitFile): to disable the actual emission of the file, useful for server-side packagesBreaking Changes
Additional Info
In order to test an use case demonstration was prepared.
It generates 3 compilations for the same source, with different parameters
dist/current-plugin: uses the current plugin as is. Generates the
dist/ssr/index.css
, which is what the creation of the new option is trying to suppress, as the file is useless for SSRdist/intended-behaviour: uses the proposed new option
emit
. Does not generate thedist/ssr/index.css
, which is exactly what the new option is set to achievedist/proposed-alternative-1: uses the alternative proposed by @alexander-akait in #713 (comment) ("just don't use this plugin for SSR") which, while not generating the
dist/ssr/index.css
, it does that by leaving it unextracted from theindex.js
, which fails to achieve the goal.