-
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
Changes from 9 commits
36ae9a0
8592403
6367490
4582e94
4853c4e
d7310b8
a8dca41
e1943b7
57e6b23
5ac1395
7718f70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,80 @@ | ||
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 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 commonConfig = require(path.join(__dirname, '..', './config/webpack.config.common.js'))(context); | ||
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. I understand you're importing and initializing in one line, would it not be easier to import it at the top and then initialize it when it's called, within the merge? 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. ah, I see what you mean! yeah, I like that. let me give it a shot. |
||
const publicPath = commonConfig.output.publicPath; | ||
|
||
return webpackMerge(commonConfig, { | ||
|
||
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 | ||
}) | ||
] | ||
}); | ||
}; |
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 .