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 dev server #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const POLYFILLS = [
require.resolve('babel-polyfill'),
require.resolve('raf/polyfill'),
];

const HOST = '0.0.0.0';
const PORT = 3000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should pull these from process.env, and have these as default values.

const { HOST = '0.0.0.0', PORT = 3000 } = process.env; 


const MATCHES_LEADING_DOT = /^\./;
const MATCHES_LEADING_DOT_SLASHES = /^[\.\/]+/;

function validateOptions(options) {
if (!options || typeof options !== 'object' || Array.isArray(options)) {
Expand Down Expand Up @@ -223,6 +228,7 @@ function createWebpackConfig(options) {
output: {
filename: outFile,
path: outDir,
publicPath: options.outDir.replace(MATCHES_LEADING_DOT_SLASHES, ''),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add this option only to devServer

https://webpack.js.org/configuration/dev-server/#devserver-publicpath-

},
module: {
rules,
Expand All @@ -233,6 +239,12 @@ function createWebpackConfig(options) {
'^': rootDir,
},
},
devServer: {
contentBase: CWD,
port: PORT,
host: HOST,
historyApiFallback: true,
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new CircularDependencyPlugin({
Expand Down
2 changes: 2 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ describe('createWebpackConfig', () => {
expect(config.output).toEqual({
filename: 'bundle.js',
path: path.resolve(CWD, 'dist'),
publicPath: 'dist',
});

expect(config.resolve.alias).toEqual({
Expand Down Expand Up @@ -349,6 +350,7 @@ describe('createWebpackConfig', () => {
expect(config.output).toEqual({
filename: '[name]-bundle.js',
path: path.resolve(CWD, 'dist'),
publicPath: 'dist',
});

expect(config.resolve.alias).toEqual({
Expand Down