Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer unpacked code from package.json #508

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "4"
- "6"
- "node"
sudo: false
cache:
Expand Down
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "git",
"url": "git+ssh://[email protected]/LLK/scratch-vm.git"
},
"main": "./dist/node/scratch-vm.js",
"main": "./src/index.js",
"scripts": {
"build": "./node_modules/.bin/webpack --progress --colors --bail",
"coverage": "./node_modules/.bin/tap ./test/{unit,integration}/*.js --coverage --coverage-report=lcov",
Expand All @@ -23,24 +23,29 @@
"watch": "./node_modules/.bin/webpack --progress --colors --watch",
"version": "./node_modules/.bin/json -f package.json -I -e \"this.repository.sha = '$(git log -n1 --pretty=format:%H)'\""
},
"devDependencies": {
"dependencies": {
"adm-zip": "0.4.7",
"htmlparser2": "3.9.2",
"minilog": "3.1.0",
"promise": "7.1.1",
"scratch-audio": "latest",
"scratch-blocks": "latest",
"scratch-render": "latest",
"scratch-storage": "latest"
},
"devDependencies": {
"babel-core": "^6.24.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.0",
"copy-webpack-plugin": "4.0.1",
"eslint": "^3.16.0",
"eslint-config-scratch": "^3.1.0",
"expose-loader": "0.7.3",
"gh-pages": "^0.12.0",
"highlightjs": "^9.8.0",
"htmlparser2": "3.9.2",
"json": "^9.0.4",
"lodash.defaultsdeep": "4.6.0",
"minilog": "3.1.0",
"promise": "7.1.1",
"scratch-audio": "latest",
"scratch-blocks": "latest",
"scratch-render": "latest",
"scratch-storage": "latest",
"script-loader": "0.7.0",
"stats.js": "^0.17.0",
"tap": "^10.2.0",
Expand Down
61 changes: 43 additions & 18 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
var CopyWebpackPlugin = require('copy-webpack-plugin');
var defaultsDeep = require('lodash.defaultsdeep');
var fs = require('fs');
var path = require('path');
var webpack = require('webpack');

/**
* Resolve a babel plugin or preset to a real path, resolving symlinks the way that Node.js would.
* Helps work around the differences between webpack's module lookup and Node's when `npm link` is in use.
* @param {string} prefix - 'babel-plugin' for a plugin, 'babel-preset' for a preset, etc.
* @param {string|Array} item - either a plugin/preset name or path or an array with such a string at index 0.
* @returns {string|Array} - the same type as `item` but the name/path will be replaced with an absolute path.
*/
const babelRealPath = function (prefix, item) {
if (typeof item === 'string') {
if (item.indexOf(prefix) !== 0) {
item = [prefix, item].join('-');
}
return fs.realpathSync(require.resolve(item));
}
item[0] = babelRealPath(prefix, item[0]);
return item;
};

var base = {
devServer: {
contentBase: false,
host: '0.0.0.0',
port: process.env.PORT || 8073
},
devtool: 'source-map',
devtool: 'cheap-module-source-map',

This comment was marked as abuse.

module: {
rules: [
{
include: [
path.resolve(__dirname, 'node_modules', 'scratch-audio', 'src'),
path.resolve(__dirname, 'node_modules', 'scratch-render', 'src'),
path.resolve(__dirname, 'node_modules', 'scratch-storage', 'src'),
path.resolve(__dirname, 'src')
].map(x => fs.realpathSync(x)),
test: /\.js$/,
loader: 'babel-loader',
options: {
presets: [
'es2015'
].map(x => babelRealPath('babel-preset', x))
}
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
Expand All @@ -31,25 +69,12 @@ module.exports = [
filename: '[name].js'
},
module: {
rules: [
rules: base.module.rules.concat([
{
test: require.resolve('./src/index.js'),
loader: 'expose-loader?VirtualMachine'
}
]
}
}),
// Node-compatible
defaultsDeep({}, base, {
target: 'node',
entry: {
'scratch-vm': './src/index.js'
},
output: {
library: 'VirtualMachine',
libraryTarget: 'commonjs2',
path: path.resolve(__dirname, 'dist/node'),
filename: '[name].js'
])
}
}),
// Playground
Expand Down Expand Up @@ -77,7 +102,7 @@ module.exports = [
filename: '[name].js'
},
module: {
loaders: [
rules: base.module.rules.concat([
{
test: require.resolve('./src/index.js'),
loader: 'expose-loader?VirtualMachine'
Expand Down Expand Up @@ -106,7 +131,7 @@ module.exports = [
test: require.resolve('scratch-storage'),
loader: 'expose-loader?Scratch.Storage'
}
]
])
},
plugins: base.plugins.concat([
new CopyWebpackPlugin([{
Expand Down