question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

publicPath not doing anything

See original GitHub issue

This might be related to #222.

  • Operating System: Windows 10
  • Node Version: v10.12.0
  • NPM Version: v6.9.0
  • webpack Version: v4.32.2
  • mini-css-extract-plugin Version: v0.6.0

Expected Behavior

publicPath should overwrite the output directory specified in output.path

Actual Behavior

Using publicPath doesn’t seem to do anything. If it’s defined as a function it does get called, but the return value is never used.

Code

module: {
	rules: [
		{
			test: /\.tsx?$/,
			use: 'ts-loader',
			exclude: /node_modules/
		},
		
		{
			test: /\.s?css$/,
			use: [
				{
					loader: MiniCssExtractPlugin.loader,
					options: {
						publicPath: 'any/path/absolute/or/relative'
					}
				},
				'css-loader'
			]
		}
	]
}

Full config

How Do We Reproduce?

By using the configuration above.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
alexander-akaitcommented, Jul 25, 2019

Please create minimum reproducible test repo

9reactions
alessiofachechicommented, Oct 1, 2019

Despite I landed here for the same reason described by @HoldYourWaffle, now that I’ve better read the docs of both MiniCssExtractPlugin and webpack.output I think that there’s a misunderstanding about the expected behavior of the plugin’s publicPath option.

What we’re currently expecting from the publicPath option is what in the case of webpack.output is done by path. But webpack.output allows for publicPath too. According to the docs the former is the output directory as an absolute path, while the latter specifies the public URL of the output directory when referenced in a browser.

In a few words what we wanted here is path, not publicPath. And the path behavior can be achieved through the plugin filename option, as already said in some comments above.

  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
  },
  plugins: [
    new MiniCssExtractPlugin({
      // path relative to the output.path
      // e.g. assets/style/main.css => dist/assets/style/main.css
      filename: 'assets/style/[name].css',
    })
  ],
Read more comments on GitHub >

github_iconTop Results From Across the Web

MiniCssExtractPlugin public path not working - Stack Overflow
I have given publicPath option for MiniCssExtractPlugin but it is not taking this option value, it is taking output.publicPath option.
Read more >
Webpack — Understanding the 'publicPath' mystery - Medium
Webpack has been initialised using a configuration object that does not match the API schema. - configuration.output.path: The provided value ".
Read more >
Public Path - webpack
The publicPath configuration option can be quite useful in a variety of scenarios. It allows you to specify the base path for all...
Read more >
Change publicPath - Released - Frontity Community Forum
so that I am not restricted to the /static folder. As a Frontity developer ... When you had it working as a query...
Read more >
Public Path Problem | ilc-sdk - GitHub Pages
However, all those approaches does not support SSR. All of them use URL of the currently executed JS file in order to try...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found