-
Notifications
You must be signed in to change notification settings - Fork 10
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
Technical/issue 11 config refactor #43
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
36ae9a0
refactored config and compilation, build task is working
thescientist13 8592403
spec refactoring
thescientist13 6367490
enable more tests
thescientist13 4582e94
enable more tests
thescientist13 4853c4e
all tests passing
thescientist13 d7310b8
remove comment
thescientist13 a8dca41
develop task working
thescientist13 e1943b7
refactor webpack common / prod config
thescientist13 57e6b23
refactor webpack common / develop config
thescientist13 5ac1395
hoist common config require to top of file
thescientist13 7718f70
test: consolidating package directory contexts (#51)
hutchgrant 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
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 |
---|---|---|
@@ -1,81 +1,81 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const commonConfig = require('./webpack.config.common'); | ||
const webpackMerge = require('webpack-merge'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const ManifestPlugin = require('webpack-manifest-plugin'); | ||
const FilewatcherPlugin = require('filewatcher-webpack-plugin'); | ||
const generateBuild = require('../lib/generate'); | ||
const generateCompilation = require('../lib/compile'); | ||
const webpackMerge = require('webpack-merge'); | ||
const commonConfig = require(path.join(__dirname, '..', './config/webpack.config.common.js')); | ||
|
||
const host = 'localhost'; | ||
const port = 1981; | ||
const publicPath = commonConfig.publicPath; | ||
let isRebuilding = false; | ||
|
||
// TODO get userWorkspace and pagesDir from greenwood config? | ||
// https://github.com/ProjectEvergreen/greenwood/issues/11 | ||
|
||
const userWorkspace = fs.existsSync(path.join(process.cwd(), 'src')) | ||
? path.join(process.cwd(), 'src') | ||
: path.join(__dirname, '..', 'templates/'); | ||
|
||
const rebuild = async() => { | ||
if (!isRebuilding) { | ||
isRebuilding = true; | ||
|
||
// rebuild web components | ||
await generateBuild(); | ||
await generateCompilation(); | ||
|
||
// debounce | ||
setTimeout(() => { | ||
isRebuilding = false; | ||
}, 1000); | ||
} | ||
}; | ||
|
||
module.exports = webpackMerge(commonConfig, { | ||
|
||
mode: 'development', | ||
module.exports = (context) => { | ||
const configWithContext = commonConfig(context); | ||
const publicPath = configWithContext.output.publicPath; | ||
|
||
return webpackMerge(configWithContext, { | ||
|
||
mode: 'development', | ||
|
||
entry: [ | ||
`webpack-dev-server/client?http://${host}:${port}`, | ||
path.join(process.cwd(), '.greenwood', 'app', 'app.js') | ||
], | ||
entry: [ | ||
`webpack-dev-server/client?http://${host}:${port}`, | ||
path.join(context.scratchDir, 'app', 'app.js') | ||
], | ||
|
||
devServer: { | ||
port, | ||
host, | ||
historyApiFallback: true, | ||
hot: false, | ||
inline: true | ||
}, | ||
devServer: { | ||
port, | ||
host, | ||
historyApiFallback: true, | ||
hot: false, | ||
inline: true | ||
}, | ||
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. These variables devServer: { port, host } should potentially be handled by config. |
||
|
||
plugins: [ | ||
// new webpack.HotModuleReplacementPlugin(), | ||
new FilewatcherPlugin({ | ||
watchFileRegex: [`/${userWorkspace}/`], | ||
onReadyCallback: () => { | ||
console.log(`Now serving Development Server available at http://${host}:${port}`); | ||
}, | ||
// eslint-disable-next-line no-unused-vars | ||
onChangeCallback: async (path) => { | ||
rebuild(); | ||
}, | ||
usePolling: true, | ||
atomic: true, | ||
ignored: '/node_modules/' | ||
}), | ||
new ManifestPlugin({ | ||
fileName: 'manifest.json', | ||
publicPath | ||
}), | ||
new HtmlWebpackPlugin({ | ||
filename: 'index.html', | ||
template: '.greenwood/index.dev.html', | ||
publicPath | ||
}), | ||
new HtmlWebpackPlugin({ | ||
filename: '404.html', | ||
template: '.greenwood/404.dev.html', | ||
publicPath | ||
}) | ||
] | ||
}); | ||
plugins: [ | ||
// new webpack.HotModuleReplacementPlugin(), | ||
new FilewatcherPlugin({ | ||
watchFileRegex: [`/${context.userWorkspace}/`], | ||
onReadyCallback: () => { | ||
console.log(`Now serving Development Server available at http://${host}:${port}`); | ||
}, | ||
// eslint-disable-next-line no-unused-vars | ||
onChangeCallback: async () => { | ||
rebuild(); | ||
}, | ||
usePolling: true, | ||
atomic: true, | ||
ignored: '/node_modules/' | ||
}), | ||
new ManifestPlugin({ | ||
fileName: 'manifest.json', | ||
publicPath | ||
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. these should use consolidated config's publicPath |
||
}), | ||
// TODO magic string paths (index.html) | ||
new HtmlWebpackPlugin({ | ||
filename: 'index.html', | ||
template: path.join(context.scratchDir, 'index.dev.html'), | ||
publicPath | ||
}), | ||
// TODO magic string paths (404.html) | ||
new HtmlWebpackPlugin({ | ||
filename: '404.html', | ||
template: path.join(context.scratchDir, '404.dev.html'), | ||
publicPath | ||
}) | ||
] | ||
}); | ||
}; |
Oops, something went wrong.
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.
This is the wrong place to hardcode this. Say I want site to run from mydomain.com/mysite/ as root path, well then '/' will lead to incorrect assets (such as manifest) etc. When I said this should be from the config, I meant the overall package config. You're calling it(what I was referring to as config) context now, assuming you'll add a separate config object, in addition to the context object, as part of the compilation object. You can see how I did this in my version of this PR
Certainly this should default to '/', but it should be configurable outside of webpack, by a user if they want. That's in addition to devServer var such host and port(Iwho knows, someone could have that port reserved or want to host on a network), etc. The issue was consolidating the config afterall.
All the other webpack configs are now relying on this publicPath(which is hardcoded).
I assume though you want to address this in #40 and leave it. Just be forewarned, when #40 is addressed, there will be things like this that will have to be modified as well.
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.
for sure. please make an issue. configuration should be reviewed / implemented on a per item basis, so it would have to come after #40 .