From 3625a0178a65a5c551de4149d66a56aee9594c75 Mon Sep 17 00:00:00 2001 From: Niels de Jong Date: Tue, 29 Nov 2022 11:10:46 +0000 Subject: [PATCH 1/2] Changed build script to use mimimal (no source map) deployment --- .github/workflows/develop-deployment.yml | 2 +- .github/workflows/master-deployment.yml | 8 ++--- Dockerfile | 2 +- package.json | 1 + webpack.config.js | 37 ++++++++++++------------ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.github/workflows/develop-deployment.yml b/.github/workflows/develop-deployment.yml index 44edfe8d2..1519667c5 100644 --- a/.github/workflows/develop-deployment.yml +++ b/.github/workflows/develop-deployment.yml @@ -44,7 +44,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: yarn install - - run: PRODUCTION=true && yarn run build + - run: yarn run build-minimal - name: Set AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: diff --git a/.github/workflows/master-deployment.yml b/.github/workflows/master-deployment.yml index a6465136d..293be94fb 100644 --- a/.github/workflows/master-deployment.yml +++ b/.github/workflows/master-deployment.yml @@ -46,7 +46,7 @@ jobs: # node-version: ${{ matrix.node-version }} # - run: rm -rf docs # - run: yarn install -# - run: yarn run build +# - run: yarn run build-minimal # - name: Set AWS credentials # uses: aws-actions/configure-aws-credentials@v1 # with: @@ -92,8 +92,8 @@ jobs: # with: # node-version: ${{ matrix.node-version }} # - run: rm -rf docs -# - run: yarn install -# - run: yarn run build +# - run: yarn install-minimal +# - run: yarn run build-minimal # - run: curl ${{ secrets.INDEX_HTML_DEPLOYMENT_URL }} > dist/index.html # - run: npm pack # - run: rm -rf target @@ -128,7 +128,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: cd gallery && yarn install - - run: cd gallery && CI=false yarn run build + - run: cd gallery && yarn run build - name: Set AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: diff --git a/Dockerfile b/Dockerfile index 47816cb62..e5672110a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY ./package.json /usr/local/src/neodash/package.json RUN yarn install COPY ./ /usr/local/src/neodash -RUN PRODUCTION=true && yarn run build +RUN yarn run build-minimal # production stage FROM nginx:alpine AS neodash diff --git a/package.json b/package.json index c49928c09..6e70ff60c 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "dev": "yarn webpack-dev-server --mode development", "debug": "yarn --node-options='--inspect' webpack-dev-server --mode development", "build": "yarn webpack --mode production && cp -r public/* dist/", + "build-minimal": "yarn webpack --mode production --env production && cp -r public/* dist/", "test": "yarn cypress open", "test-headless": "yarn cypress run" }, diff --git a/webpack.config.js b/webpack.config.js index e0e7f5ff7..6fae47720 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,8 +1,6 @@ const path = require('path'); const webpack = require('webpack'); -const production = process.env.PRODUCTION === 'true'; - const rules = [{ test: /\.(js|jsx|ts|tsx)$/, exclude: /(node_modules)/, @@ -25,20 +23,23 @@ const rules = [{ }] -module.exports = { - entry: './src/index.tsx', - mode: production ? 'production' : 'development', - devtool: production ? undefined : 'source-map', - module: { - rules: rules - }, - resolve: { extensions: ['*', '.js', '.jsx', '.ts', '.tsx'] }, - output: { - filename: 'bundle.js' - }, - devServer: { - port: 3000, - hot: true - }, - plugins: [new webpack.HotModuleReplacementPlugin()] +module.exports = (env) => { + const production = env.production; + return { + entry: './src/index.tsx', + mode: production ? 'production' : 'development', + devtool: production ? undefined : 'source-map', + module: { + rules: rules + }, + resolve: { extensions: ['*', '.js', '.jsx', '.ts', '.tsx'] }, + output: { + filename: 'bundle.js' + }, + devServer: { + port: 3000, + hot: true + }, + plugins: [new webpack.HotModuleReplacementPlugin()] + } }; \ No newline at end of file From d7be82c40368211385d1371ddcea5e5cb4adb202 Mon Sep 17 00:00:00 2001 From: Niels de Jong Date: Fri, 16 Dec 2022 10:45:57 +0100 Subject: [PATCH 2/2] Added TODOs based on comments --- webpack.config.js | 65 +++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 6fae47720..ce7d21bdc 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,45 +1,48 @@ const path = require('path'); const webpack = require('webpack'); -const rules = [{ +const rules = [ + { test: /\.(js|jsx|ts|tsx)$/, exclude: /(node_modules)/, loader: 'babel-loader', - options: { presets: ["@babel/env"] } -}, -{ + options: { presets: ['@babel/env'] }, + }, + { test: /\.css$/, - use: ["style-loader", "css-loader"] -}, -{ + use: ['style-loader', 'css-loader'], + }, + { test: /\.js$/, exclude: /(node_modules\/react-leaflet-heatmap-layer-v3)/, enforce: 'pre', use: ['source-map-loader'], -}, -{ + }, + { test: /.(png|svg|jpe?g|gif|woff2?|ttf|eot)$/, - use: ['file-loader'] -}] - + use: ['file-loader'], + }, +]; +// TODO - move this config to a dedicated environment file. +// TODO - use process.env.NODE_ENV which will directly return the environment string "development", "production". module.exports = (env) => { - const production = env.production; - return { - entry: './src/index.tsx', - mode: production ? 'production' : 'development', - devtool: production ? undefined : 'source-map', - module: { - rules: rules - }, - resolve: { extensions: ['*', '.js', '.jsx', '.ts', '.tsx'] }, - output: { - filename: 'bundle.js' - }, - devServer: { - port: 3000, - hot: true - }, - plugins: [new webpack.HotModuleReplacementPlugin()] - } -}; \ No newline at end of file + const production = env.production; + return { + entry: './src/index.tsx', + mode: production ? 'production' : 'development', + devtool: production ? undefined : 'source-map', + module: { + rules: rules, + }, + resolve: { extensions: ['*', '.js', '.jsx', '.ts', '.tsx'] }, + output: { + filename: 'bundle.js', + }, + devServer: { + port: 3000, + hot: true, + }, + plugins: [new webpack.HotModuleReplacementPlugin()], + }; +};