-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from datamade/feature/webpack
replace django compressor with webpack in the django cookiecutter template
- Loading branch information
Showing
10 changed files
with
168 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
docker/templates/new-django-app/{{cookiecutter.app_name}}/Dockerfile.dev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM node:18 AS webpack | ||
|
||
# Give ourselves some credit | ||
LABEL maintainer "DataMade <[email protected]>" | ||
|
||
# Inside the container, create an app directory and switch into it | ||
RUN mkdir /app | ||
WORKDIR /app | ||
|
||
# Install Node requirements | ||
COPY ./package.json /app/package.json | ||
RUN npm install | ||
|
||
FROM python:3.10 AS app | ||
|
||
LABEL maintainer "DataMade <[email protected]>" | ||
|
||
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - | ||
|
||
RUN apt-get install -y --no-install-recommends postgresql-client nodejs{% if cookiecutter.postgis == 'True' %} gdal-bin{% endif %} | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
|
||
COPY ./requirements.txt /app/requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY --from=webpack /app/node_modules /app/node_modules | ||
|
||
COPY . /app | ||
|
||
# Add a bogus env var for the Django secret key in order to allow us to run | ||
# the 'collectstatic' management command | ||
ENV DJANGO_SECRET_KEY 'foobar' | ||
RUN python manage.py collectstatic --noinput |
Empty file.
20 changes: 18 additions & 2 deletions
20
docker/templates/new-django-app/{{cookiecutter.app_name}}/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
docker/templates/new-django-app/{{cookiecutter.app_name}}/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const path = require("path") | ||
const webpack = require("webpack") // eslint-disable-line no-unused-vars | ||
const BundleTracker = require("webpack-bundle-tracker") | ||
|
||
const config = { | ||
context: __dirname, | ||
entry: { | ||
base: "./{{cookiecutter.module_name}}/static/js/base.js", | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, "assets/bundles/"), | ||
filename: "[name]-[hash].js", | ||
chunkFilename: "[name]-[hash].js", | ||
}, | ||
plugins: [ | ||
new BundleTracker({ | ||
path: __dirname, | ||
filename: "webpack-stats.json" | ||
}) | ||
], | ||
devServer: { | ||
watchFiles: ["{{cookiecutter.app_name}}/static/**/*.js"], | ||
host: "0.0.0.0", | ||
port: 3000, | ||
compress: false, | ||
allowedHosts: ["localhost"], | ||
}, | ||
watchOptions: { | ||
poll: 1000, | ||
}, | ||
resolve: { | ||
extensions: [".js", ".jsx", ".geojson"], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(js|jsx)$/, | ||
exclude: /node_modules/, | ||
loader: "babel-loader", | ||
options: { | ||
presets: ["@babel/preset-env", "@babel/preset-react"] | ||
}, | ||
}, | ||
{ | ||
test: /\.geojson$/, | ||
type: "json", | ||
}, | ||
{ | ||
test: /\.css$/i, | ||
use: [ | ||
// Creates `style` nodes from JS strings | ||
"style-loader", | ||
// Translates CSS into CommonJS | ||
"css-loader", | ||
], | ||
}, | ||
{ | ||
test: /\.(jpg|png|mp4)$/, | ||
use: { | ||
loader: "url-loader", | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
module.exports = (env, argv) => { | ||
/* | ||
* /app/webpack-stats.json is the roadmap for the assorted chunks of JS | ||
* produced by Webpack. During local development, the Webpack server | ||
* serves our bundles. In production, Django should look in | ||
* /app/static/bundles for bundles. | ||
*/ | ||
if (argv.mode === "development") { | ||
config.output.publicPath = "http://localhost:3000/static/bundles/" | ||
} | ||
|
||
if (argv.mode === "production") { | ||
config.output.publicPath = "/static/bundles/" | ||
} | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters