Skip to content

Commit

Permalink
massively simplified webpack.js (#295)
Browse files Browse the repository at this point in the history
* massively simplified webpack.js
  • Loading branch information
paddymul authored Oct 12, 2024
1 parent 57b850b commit 0fd9aec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 109 deletions.
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,22 @@
"url": "https://github.com/paddymul/buckaroo"
},
"scripts": {
"build": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension",
"build-full": "yarn run build:lib && run build:nbextension && yarn run build:labextension",
"build:dev": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension:dev",
"build": "yarn run build:lib && yarn run build:labextension",
"build:dev": "yarn run build:lib && yarn run build:labextension:dev",
"build:labextension": "jupyter labextension build .",
"build:labextension:dev": "which jupyter && jupyter labextension build --development True .",
"build:lib": "tsc",
"build:nbextension": "webpack --mode=production --no-devtool",
"build:widget-examples": "cd widget-examples/basic && webpack --mode=production",
"build:examples": "webpack --mode=production --config docs/webpack.typescript.localdev.ts --env production",
"build:all": "yarn run build:labextension && yarn run build:nbextension && yarn run build:widget-examples",
"clean": "rimraf dist && yarn run clean:lib && yarn run clean:labextension && yarn run clean:nbextension",
"build:all": "yarn run build:labextension",
"clean": "rimraf dist && yarn run clean:lib && yarn run clean:labextension",
"clean:lib": "rimraf lib",
"clean:labextension": "rimraf buckaroo/labextension",
"clean:nbextension": "rimraf buckaroo/nbextension/index.*",
"lint": "eslint 'js/**/*.{ts,tsx}'",
"lint:check": "eslint 'js/**/*.{ts,tsx}'",
"lint:fix": "eslint 'js/**/*.{ts,tsx}' --fix",
"prepack": "yarn run build:labextension && yarn run build:nbextension",
"test": "jest --verbose --passWithNoTests",
"watch": "npm-run-all -p watch:*",
"watch:lib": "tsc -w",
"watch:nbextension": "webpack --watch",
"watch:labextension": "jupyter labextension watch .",
"dev": "webpack-cli serve --config docs/webpack.typescript.localdev.ts --mode=development --env development --open"
},
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ Homepage = "https://github.com/paddymul/buckaroo"

[tool.hatch.build]
artifacts = [
"buckaroo/nbextension/index.*",
"buckaroo/labextension",
]

[tool.hatch.build.targets.wheel.shared-data]
"buckaroo/nbextension" = "share/jupyter/nbextensions/buckaroo"
"buckaroo/labextension" = "share/jupyter/labextensions/buckaroo"
"buckaroo.json" = "etc/jupyter/nbconfig/notebook.d/buckaroo.json"

Expand All @@ -106,7 +104,6 @@ exclude = [
[tool.hatch.build.hooks.jupyter-builder]

ensured-targets = [
"buckaroo/nbextension/index.js",
"buckaroo/labextension/package.json",
]
dependencies = ["hatch-jupyter-builder>=0.8.1"]
Expand Down
109 changes: 13 additions & 96 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const version = require('./package.json').version;
//import {TsconfigPathsPlugin} from 'tsconfig-paths-webpack-plugin';
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

//import HtmlWebpackPlugin from 'html-webpack-plugin';
const HtmlWebpackPlugin = require('html-webpack-plugin');
Expand All @@ -14,35 +14,15 @@ const cryptoOrigCreateHash = crypto.createHash;
crypto.createHash = (algorithm) =>
cryptoOrigCreateHash(algorithm == 'md4' ? 'sha256' : algorithm);

const performance = {
maxAssetSize: 100_000_000,
const performance = {
maxAssetSize: 100_000_000,
};

// Custom webpack rules
const baseRules = [

const rules = [
{ test: /\.tsx?$/, loader: 'ts-loader' },
{ test: /\.js$/, loader: 'source-map-loader' },
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{
test: /\.scss$/,
use: [
// We're in dev and want HMR, SCSS is handled in JS
// In production, we want our css as files
"style-loader",
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
["postcss-preset-env"],
],
},
},
},
"sass-loader"
],
},
{
test: luminoThemeImages,
issuer: /\.css$/,
Expand All @@ -55,10 +35,10 @@ const baseRules = [
exclude: luminoThemeImages,
use: ['file-loader'],
},
{
test: /\.md$/,
use: ['html-loader', 'markdown-loader']
},
{
test: /\.md$/,
use: ['html-loader', 'markdown-loader'],
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: /\.css$/,
Expand All @@ -70,56 +50,17 @@ const baseRules = [
];


const rules = [...baseRules, { test: /\.tsx?$/, loader: 'ts-loader' }];
const demoRules = [...baseRules,
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
configFile: 'examples/tsconfig.json'
}
}]


// Packages that shouldn't be bundled but loaded at runtime
const externals = ['@jupyter-widgets/base'];

const resolve = {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.webpack.js', '.web.js', '.ts', '.js', '.tsx'],
plugins: [new TsconfigPathsPlugin()],
plugins: [new TsconfigPathsPlugin()],
fallback: { crypto: false },
};

module.exports = [
/**
* Notebook extension
*
* This bundle only contains the part of the JavaScript that is run on load of
* the notebook.
*/
{
entry: './js/extension.ts',
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'buckaroo', 'nbextension'),
libraryTarget: 'amd',
},
module: {
rules: rules,
},
devtool: 'source-map',
externals,
resolve,
// plugins: [new HtmlWebpackPlugin({
// template: './examples/index.html'
// })]
performance


},

/**
* Embeddable buckaroo bundle
*
Expand All @@ -145,33 +86,9 @@ module.exports = [
},
externals,
resolve,
devServer: {
port: 8030
},
performance

},

/**
* Documentation widget bundle
*
* This bundle is used to embed widgets in the package documentation.
*/
{
entry: './js/index.ts',
output: {
filename: 'embed-bundle.js',
path: path.resolve(__dirname, 'docs', 'source', '_static'),
library: 'buckaroo',
libraryTarget: 'amd',
},
module: {
rules: rules,
devServer: {
port: 8030,
},
devtool: 'source-map',
externals,
resolve,
performance

performance,
},
];

0 comments on commit 0fd9aec

Please sign in to comment.