From 4c1eea3b0910d1751a5d94eaa6e5c250e225d94a Mon Sep 17 00:00:00 2001 From: Nikolaev Tomov Date: Tue, 11 Sep 2018 11:46:14 +0100 Subject: [PATCH 1/6] Proxy js file to index.html --- src/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.js b/src/index.js index 6b02584..964173b 100644 --- a/src/index.js +++ b/src/index.js @@ -214,6 +214,16 @@ function createWebpackConfig(options) { '^': rootDir, }, }, + devServer: { + contentBase: entry, + port: 3000, + inline: options.livePageReload, + proxy: { + '*': { + target: 'http://[::1]', + } + } + }, plugins: [ new ForkTsCheckerWebpackPlugin(), new CircularDependencyPlugin({ From f43900ddb053cb6b1120981af8d5d86a34d6b1b2 Mon Sep 17 00:00:00 2001 From: Nikolaev Tomov Date: Mon, 17 Sep 2018 14:11:47 +0100 Subject: [PATCH 2/6] imporve wds --- src/index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 964173b..dc03173 100644 --- a/src/index.js +++ b/src/index.js @@ -8,7 +8,12 @@ const POLYFILLS = [ require.resolve('babel-polyfill'), require.resolve('raf/polyfill'), ]; + +const HOST = '0.0.0.0'; +const PORT = 3000; + const MATCHES_LEADING_DOT = /^\./; +const MATCHES_LEADING_DOT_SLASHES = /^[\.\/]+/; function validateOptions(options) { if (!options || typeof options !== 'object' || Array.isArray(options)) { @@ -204,6 +209,7 @@ function createWebpackConfig(options) { output: { filename: outFile, path: outDir, + publicPath: options.outDir.replace(MATCHES_LEADING_DOT_SLASHES, ''), }, module: { rules, @@ -215,14 +221,9 @@ function createWebpackConfig(options) { }, }, devServer: { - contentBase: entry, - port: 3000, - inline: options.livePageReload, - proxy: { - '*': { - target: 'http://[::1]', - } - } + contentBase: CWD, + port: PORT, + host: HOST, }, plugins: [ new ForkTsCheckerWebpackPlugin(), From 7fcb0a1c7aec1f64f04ce9acdb5cdc1028041c93 Mon Sep 17 00:00:00 2001 From: Nikolaev Tomov Date: Mon, 17 Sep 2018 14:54:39 +0100 Subject: [PATCH 3/6] Fix test --- tests/index.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/index.test.js b/tests/index.test.js index 5b38ad6..c3dc4fe 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -275,6 +275,7 @@ describe('createWebpackConfig', () => { expect(config.output).toEqual({ filename: 'bundle.js', path: path.resolve(CWD, 'dist'), + publicPath: 'dist', }); expect(config.resolve.alias).toEqual({ @@ -312,6 +313,7 @@ describe('createWebpackConfig', () => { expect(config.output).toEqual({ filename: '[name]-bundle.js', path: path.resolve(CWD, 'dist'), + publicPath: 'dist', }); expect(config.resolve.alias).toEqual({ From ee5d3dab8c01485547dfe3be6d285baabc351aa6 Mon Sep 17 00:00:00 2001 From: Nikolaev Tomov Date: Wed, 19 Sep 2018 11:30:27 +0100 Subject: [PATCH 4/6] Additional fix for react-router on dev environment --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index dc03173..f5dac90 100644 --- a/src/index.js +++ b/src/index.js @@ -224,6 +224,7 @@ function createWebpackConfig(options) { contentBase: CWD, port: PORT, host: HOST, + historyApiFallback: true, }, plugins: [ new ForkTsCheckerWebpackPlugin(), From d6514f5fbad43845b0a9da1acc9fe99b8c29816a Mon Sep 17 00:00:00 2001 From: Nikolaev Tomov Date: Tue, 9 Oct 2018 14:09:16 +0100 Subject: [PATCH 5/6] move publickPath to devserver only, destructure port and host from process.env and specify default values --- src/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index f5dac90..70dfe4e 100644 --- a/src/index.js +++ b/src/index.js @@ -9,8 +9,7 @@ const POLYFILLS = [ require.resolve('raf/polyfill'), ]; -const HOST = '0.0.0.0'; -const PORT = 3000; +const { HOST = '0.0.0.0', PORT = 3000 } = process.env; const MATCHES_LEADING_DOT = /^\./; const MATCHES_LEADING_DOT_SLASHES = /^[\.\/]+/; @@ -209,7 +208,6 @@ function createWebpackConfig(options) { output: { filename: outFile, path: outDir, - publicPath: options.outDir.replace(MATCHES_LEADING_DOT_SLASHES, ''), }, module: { rules, @@ -222,6 +220,7 @@ function createWebpackConfig(options) { }, devServer: { contentBase: CWD, + publicPath: options.outDir.replace(MATCHES_LEADING_DOT_SLASHES, ''), port: PORT, host: HOST, historyApiFallback: true, From 8c206face0435eccec170e4f228dd99be2799262 Mon Sep 17 00:00:00 2001 From: Nikolaev Tomov Date: Tue, 9 Oct 2018 14:18:36 +0100 Subject: [PATCH 6/6] Udpate the test for publicPath whch was moved to dev-server --- tests/index.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/index.test.js b/tests/index.test.js index a153dd3..968b5e0 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -312,7 +312,6 @@ describe('createWebpackConfig', () => { expect(config.output).toEqual({ filename: 'bundle.js', path: path.resolve(CWD, 'dist'), - publicPath: 'dist', }); expect(config.resolve.alias).toEqual({ @@ -350,7 +349,6 @@ describe('createWebpackConfig', () => { expect(config.output).toEqual({ filename: '[name]-bundle.js', path: path.resolve(CWD, 'dist'), - publicPath: 'dist', }); expect(config.resolve.alias).toEqual({