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

Ensure output path exists and write all handled files #2

Closed
majodev opened this issue Nov 1, 2015 · 15 comments
Closed

Ensure output path exists and write all handled files #2

majodev opened this issue Nov 1, 2015 · 15 comments
Assignees
Labels

Comments

@majodev
Copy link

majodev commented Nov 1, 2015

Hi,

Your plugin currently throws if the specified output directory was not created before (or cleaned via another plugin at the start) and does not handle assets that were not part of a chunk. I think @sretlawd fixes this quite nicely in his fork, you might wanna take a look at it and merge back...

see: https://github.com/sretlawd/write-file-webpack-plugin/commit/0ccdacdc0612f0f362c151cef88685292ee81093

Anyways, Thank you for this plugin. 👍

@gajus
Copy link
Owner

gajus commented Nov 1, 2015

I will happily accept a PR.

On Nov 1, 2015, at 19:12, Mario Ranftl notifications@github.com wrote:

Hi,

Your plugin currently throws if the specified output directory was not created before (or cleaned via another plugin at the start) and does not handle assets that were not part of a chunk. I think @sretlawd fixes this quite nicely in his fork, you might wanna take a look at it and merge back...

see: sretlawd@0ccdacd

Anyways, Thank you for this plugin.


Reply to this email directly or view it on GitHub.

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

@chrisblossom, @majodev, @sretlawd please see if v2 solves the problem.

@gajus gajus added the bug label Dec 7, 2015
@gajus gajus self-assigned this Dec 7, 2015
@chrisblossom
Copy link
Contributor

@gajus I am actually not using the webpack-dev-server package. Can this devServer.outputPath change be optional?

Also, the option to only write specific extensions, specifically only .css, was removed from this PR which was in mine. Would you accept a pull request with this functionality built on 2.0?

EDIT: FYI, I am using https://github.com/erikras/react-redux-universal-hot-example for a boilerplate.

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

EDIT: FYI, I am using https://github.com/erikras/react-redux-universal-hot-example for a boilerplate.

Does this not have the issue described here? #1

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

Also, the option to only write specific extensions, specifically only .css, was removed from this PR which was in mine. Would you accept a pull request with this functionality built on 2.0?

Please open a new issue. The reason it was "removed" is because it has not been discussed as a separate issue.

@chrisblossom
Copy link
Contributor

#1 does not appear to be an issue when not using webpack-dev-server.

console.log(compiler.options.output);

{ path: '/Users/chris/github/website/static/dist',
  filename: '[name]-[hash].js',
  chunkFilename: '[name]-[chunkhash].js',
  publicPath: 'http://localhost:3001/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 }

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

I think that having devServer.outputPath does not hurt anyone and it makes the configuration work regardless of the execution context. I would not want my instructions to produce different results depending on the implementation of the program.

Therefore, unless someone gives a good reason not to, I will be keeping the devServer.outputPath solution.

The ideal solution would be contributing a fix to the https://github.com/webpack/webpack-dev-server.

@chrisblossom
Copy link
Contributor

When adding "devServer: {outputPath: assetsPath}, " to my config I am getting the following error:

[0] Error: no such file or directory
[0]     at MemoryFileSystem.readFileSync (/Users/chris/github/website/node_modules/memory-fs/lib/MemoryFileSystem.js:114:10)
[0]     at /Users/chris/github/website/node_modules/write-file-webpack-plugin/dist/index.js:77:52
[0]     at arrayEach (/Users/chris/github/website/node_modules/lodash/internal/arrayEach.js:15:9)
[0]     at /Users/chris/github/website/node_modules/lodash/internal/createForEach.js:15:9
[0]     at Compiler.<anonymous> (/Users/chris/github/website/node_modules/write-file-webpack-plugin/dist/index.js:71:31)
[0]     at Compiler.applyPlugins (/Users/chris/github/website/node_modules/tapable/lib/Tapable.js:26:37)
[0]     at Watching._done (/Users/chris/github/website/node_modules/webpack/lib/Compiler.js:78:17)
[0]     at Watching.<anonymous> (/Users/chris/github/website/node_modules/webpack/lib/Compiler.js:61:18)
[0]     at Compiler.emitRecords (/Users/chris/github/website/node_modules/webpack/lib/Compiler.js:282:37)
[0]     at Watching.<anonymous> (/Users/chris/github/website/node_modules/webpack/lib/Compiler.js:58:19)
console.log(outputPath);

[0] /Users/chris/github/website/static/dist

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

What is the name of bundleFileName?

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

Does the issue persist if you replace

bundleFilePath = path.join('/', bundleFileName);

with

bundleFilePath = path.join(outputPath, bundleFileName);

?

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

I have just pushed version 2.1.1 that implements the earlier suggestion.

@chrisblossom
Copy link
Contributor

Just a thought to make it less opinionated/remove devServer requirement:

if (compiler.options.devServer && (compiler.options.devServer.outputPath !== compiler.options.output.path)) {
    throw new Error('output.path and devServer.outputPath must be equal.');
}
outputPath = compiler.options.output.path;

Readme could say something along the lines of "If using webpack-dev-server, devServer.outputPath must equal output.path."

@chrisblossom
Copy link
Contributor

Confirmed that 2.1.1 4d2a3e5 fixed the error I was getting.

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

Confirmed that 2.1.1 4d2a3e5 fixed the error I was getting.

Thank you

@gajus
Copy link
Owner

gajus commented Dec 7, 2015

Just a thought to make it less opinionated/remove devServer requirement:

Please copy-paste you have written and open a separate issue.

@gajus gajus closed this as completed Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants