Skip to content

Commit 9499429

Browse files
committed
Adds prod webpack config. Modifies materia-app dockerfile to correctly build assets into app image.
1 parent 45c2fcb commit 9499429

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

docker/run_build_github_release_package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ docker run \
9090
--mount type=bind,source="$(pwd)"/clean_build_clone/,target=/build \
9191
--mount source=materia-asset-build-vol,target=/build/node_modules \
9292
node:18.13.0-alpine \
93-
/bin/ash -c "apk add --no-cache git && cd build && yarn install --frozen-lockfile --non-interactive --pure-lockfile --force && npm run-script build"
93+
/bin/ash -c "apk add --no-cache git && cd build && yarn install --frozen-lockfile --non-interactive --pure-lockfile --force && npm run-script build-for-image"
9494

9595
# verify all files we expect to be created exist
9696
for i in "${FILES_THAT_SHOULD_EXIST[@]}"

materia-app.Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,24 @@ COPY --chown=www-data:www-data ./oil /var/www/html/oil
6161
RUN composer install --no-cache --no-dev --no-progress --no-scripts --prefer-dist --optimize-autoloader
6262

6363
# =====================================================================================================
64-
# Yarn stage buils js/css assets
64+
# Yarn stage build js/css assets
6565
# =====================================================================================================
6666
FROM node:18.13.0-alpine AS yarn_stage
6767

6868
RUN apk add --no-cache git
6969

7070
COPY ./public /build/public
71+
# copy configs into /build. These are required for yarn and webpack
7172
COPY ./package.json /build/package.json
73+
COPY ./babel.config.json /build/babel.config.json
74+
COPY ./webpack.prod.config.js /build/webpack.prod.config.js
7275
COPY ./yarn.lock /build/yarn.lock
76+
# these directories must be hoisted into /build in order for webpack to work on them
77+
COPY ./src /build/src
78+
COPY ./fuel/packages /build/fuel/packages
7379
RUN mkdir -p /build/fuel/app/config/
74-
RUN cd build && yarn install --frozen-lockfile --non-interactive --production --silent --pure-lockfile --force
75-
80+
# run yarn install and then the build script in the package.json (webpack --config webpack.prod.config.js)
81+
RUN cd build && yarn install --frozen-lockfile --non-interactive --silent --pure-lockfile --force && npm run-script build-for-image
7682

7783
# =====================================================================================================
7884
# final stage creates the final deployable image

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"scripts": {
1313
"dev": "webpack-dev-server",
1414
"build": "webpack",
15+
"build-for-image": "webpack --config webpack.prod.config.js",
1516
"test": "TZ=Etc/UTC jest --verbose",
1617
"test:dev": "TZ=Etc/UTC jest --verbose --watch --coverage",
1718
"test:ci": "TZ=Etc/UTC CI=true jest --ci --useStderr --coverage --coverageReporters text-summary cobertura",

webpack.prod.config.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const glob = require('glob')
2+
const path = require('path')
3+
4+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
5+
const jsPath = path.join(__dirname, 'src',)
6+
const packageJsPath = path.join(__dirname, 'fuel','packages')
7+
const cssPath = path.join(__dirname, 'src', 'css')
8+
const componentCssPath = path.join(__dirname, 'src', 'components')
9+
10+
const entry = {}
11+
// Webpack Entry Point Registration Overview
12+
// Create object with:
13+
// Key = output name, Value = source sass file
14+
// for every scss file in the cssPath directory
15+
// EX: { 'css/<filename>.css' : './src/css/filename.scss', ...}
16+
17+
18+
// SASS/CSS webpack entry point registration
19+
glob.sync(path.join(cssPath, '*.scss')).forEach(file => {
20+
entry['css/'+path.basename(file, '.scss')] = file
21+
})
22+
23+
glob.sync(path.join(componentCssPath, '*.scss')).forEach(file => {
24+
entry['css/'+path.basename(file, '.scss')] = file
25+
})
26+
27+
// // JS webpack entry point registration
28+
// // locates all `js/*.js` files
29+
glob.sync(path.join(jsPath, '*.js')).map(file => {
30+
entry['js/'+path.basename(file, '.js')] = file
31+
})
32+
33+
// some packages (like the reactified materia-theme-ucf) have js that needs to be added to webpack
34+
glob.sync(path.join(packageJsPath, '**/*.js')).map(file => {
35+
entry['js/'+path.basename(file, '.js')] = file
36+
})
37+
38+
module.exports = {
39+
mode: 'production',
40+
entry,
41+
output: {
42+
path: path.join(__dirname, 'public/dist/'),
43+
filename: '[name].js',
44+
clean: true
45+
},
46+
module: {
47+
rules: [
48+
{
49+
test: /\.(js|jsx)$/,
50+
exclude: /node_modules/,
51+
use: {
52+
loader: 'babel-loader'
53+
}
54+
},
55+
{
56+
test: /\.s?css$/,
57+
use: [
58+
MiniCssExtractPlugin.loader,
59+
{
60+
loader: 'css-loader',
61+
options: {
62+
url: false
63+
}
64+
},
65+
'sass-loader'
66+
]
67+
},
68+
]
69+
},
70+
plugins: [
71+
new MiniCssExtractPlugin({
72+
filename: "[name].css"
73+
})
74+
],
75+
resolve: {
76+
extensions: ['.js', '.jsx'],
77+
}
78+
// externals: {
79+
// react: 'React',
80+
// 'react-dom': 'ReactDOM'
81+
// }
82+
}

0 commit comments

Comments
 (0)