Skip to content

Commit

Permalink
Separate examples and library files into separate build target files
Browse files Browse the repository at this point in the history
  • Loading branch information
bomanimc committed Mar 16, 2020
1 parent e065b20 commit fb5c6de
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ training/lstm/data/t
/public
/static
/dist
/dist_examples

website/translated_docs
website/build/
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"develop": "npm-run-all --parallel start examples:serve",
"start": "webpack-dev-server --config webpack.dev.babel.js",
"manual-test": "webpack-dev-server --open --config webpack.test.babel.js",
"build": "webpack --config webpack.prod.babel.js",
"build": "webpack --config webpack.prod.babel.js --config-name ml5",
"test": "./node_modules/karma/bin/karma start karma.conf.js",
"test:single": "./node_modules/karma/bin/karma start karma.conf.js --single-run",
"test-travis": "./scripts/test-travis.sh",
Expand All @@ -24,7 +24,9 @@
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"examples:serve": "live-server ./examples --port=8081 --mount=/:./examples/public",
"examples:update-json": "node scripts/update-examples-json.js"
"examples:update-json": "node scripts/update-examples-json.js",
"preexamples:build": "rimraf dist_examples",
"examples:build": "webpack --config webpack.prod.babel.js --config-name examples"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions webpack.common.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const include = join(__dirname, 'src');
export const indexEntryWithBabel = ['babel-polyfill', './src/index.js'];

export default {
name: 'ml5',
entry: indexEntryWithBabel,
output: {
path: resolve(__dirname, 'dist'),
Expand Down
15 changes: 13 additions & 2 deletions webpack.prod.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT

import merge from 'webpack-merge';
import { resolve } from 'path';
import common, {indexEntryWithBabel} from './webpack.common.babel';
import UglifyJSPlugin from 'uglifyjs-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
Expand All @@ -17,7 +18,7 @@ const replaceML5Reference = (content, path) => {
return content.toString().replace('http://localhost:8080/ml5.js', 'https://unpkg.com/ml5@latest/dist/ml5.min.js');
}

export default merge(common, {
const libraryBuildConfig = merge(common, {
mode: 'production',
devtool: 'source-map',
entry: {
Expand All @@ -35,14 +36,24 @@ export default merge(common, {
sourceMap: true,
}),
],
}
});

const exampleBuildConfig = merge(common, {
name: 'examples',
mode: 'production',
output: {
path: resolve(__dirname, 'dist_examples'),
publicPath: '/',
},
plugins: [
new CopyPlugin([
{
from: 'examples/',
to: 'examples/',
transform: (content, path) => replaceML5Reference(content, path),
},
]),
],
});

export default [libraryBuildConfig, exampleBuildConfig];

0 comments on commit fb5c6de

Please sign in to comment.