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

webpack plugin does not have access to output path when running webpack-dev-server program #1

Closed
frantic opened this issue Oct 28, 2015 · 11 comments

Comments

@frantic
Copy link

frantic commented Oct 28, 2015

For some reason the plugin picks up a wrong output path for my file, instead of ./dist I just get /.

My config:

var WriteFilePlugin = require('write-file-webpack-plugin');

module.exports = {
  entry: "./src/main.js",
  output: {
    path: __dirname + "/dist",
    filename: "bundle.js",
    publicPath: "/dist"
  },
  module: {
    loaders: [{
      test: /\.js$/,
      exclude: /(node_modules|examples)/,
      loader: 'babel-loader?stage=0'
    }]
  },
  plugins: [
    new WriteFilePlugin()
  ]
};

but the plugin creates a file in my root - /bundle.js. I've added some logging. The config exported from webpack.config.js looks like this:

{ entry: './src/main.js',
  output:
   { path: '/Users/frantic/code/flexbox/dist',
     filename: 'bundle.js',
     publicPath: '/dist' },
  module: { loaders: [ [Object] ] },
  plugins: [ { apply: [Function: apply] } ] }

however inside plugin's apply when I console.log(compiler.options); I get:

{ entry:
   [ '/usr/local/lib/node_modules/webpack-dev-server/client/index.js?http://localhost:8080',
     './src/main.js' ],
  output:
   { path: '/',
     filename: 'bundle.js',
     publicPath: '/dist',
     libraryTarget: 'var',
     sourceMapFilename: '[file].map[query]',
     hotUpdateChunkFilename: '[id].[hash].hot-update.js',
     hotUpdateMainFilename: '[hash].hot-update.json',
     crossOriginLoading: false,
     hashFunction: 'md5',
     hashDigest: 'hex',
     hashDigestLength: 20,
     sourcePrefix: '\t',
     devtoolLineToLine: false },
  module:
   { loaders: [ [Object] ],
     ...

Is it a webpack's issue?

@frantic
Copy link
Author

frantic commented Oct 28, 2015

Using v1.12.2 of webpack, which seems to be the latest.

@gajus gajus added bug and removed bug labels Oct 28, 2015
@gajus
Copy link
Owner

gajus commented Oct 28, 2015

@frantic please raise this with https://github.com/webpack/webpack and CC me.

I cannot see a reason why compiler.options.path is different from what you have defined in the webpack config.

@frantic
Copy link
Author

frantic commented Oct 28, 2015

@gajus does this work for you? Can you console.log the compiler.options you get?

@ghost
Copy link

ghost commented Oct 29, 2015

I ran into the same problem, it seems to be due to the command line wrapper webpack-dev-server forcing the output path to / here.

Commenting that bit out seems to fix it, so I just opted to skip the command line wrapper and use the API. I imagine this means it doesn't affect anyone using grunt, etc., either.

@gajus gajus changed the title Picking up a wrong path webpack plugin does not have access to output path when running webpack-dev-server program Dec 7, 2015
@gajus
Copy link
Owner

gajus commented Dec 7, 2015

This plugin will require that outputPath property is added to devServer configuration. See https://github.com/gajus/write-file-webpack-plugin#usage.

@frenic
Copy link

frenic commented Dec 15, 2015

I have this issue too. Is it possible to switch to bundleFilePath = path.join(outputPath, bundleFileName); or apply another temporarily workaround until webpack/webpack-dev-server#337 is solved?

@wyntau
Copy link
Contributor

wyntau commented Feb 17, 2016

same problem

@bartsmykla
Copy link

Same problem here

@adeacetis
Copy link

adeacetis commented Feb 2, 2017

I might be late at the party but this issue is still happening with HtmlWebpackPlugin. See issue: HtmlWebpackPlugin Issue#384
The mentioned plug-in, harddisk plugin didn't help me out either.
What is the current status on this very issue ? Is there anyone in charge ?

Here are my depedencies version:
"dependencies": { "babel": "^6.5.2", "react": "^15.4.2", "react-dom": "^15.4.2" }, "devDependencies": { "babel-cli": "^6.22.2", "babel-core": "^6.22.1", "babel-eslint": "^6.1.2", "babel-loader": "^6.2.10", "babel-plugin-transform-object-rest-spread": "^6.22.0", "babel-polyfill": "^6.22.0", "babel-preset-env": "^1.1.8", "babel-preset-es2015": "^6.22.0", "babel-preset-react": "^6.22.0", "eslint": "^3.14.1", "extract-text-webpack-plugin": "^1.0.1", "html-loader": "^0.4.4", "html-webpack-harddisk-plugin": "0.0.2", "html-webpack-plugin": "^2.28.0", "jsx-loader": "^0.13.2", "webpack": "^2.2.1" }

@volkanunsal
Copy link

Same problem here. Using webpack-dev-server 1.16.4.

@phil123456
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants