Skip to content

Commit

Permalink
feature(putout) add bundle dist/putout.js
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jun 18, 2019
1 parent 9b39f10 commit d0652b1
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/putout/.babelrc
@@ -0,0 +1,5 @@
{
"plugins": [
"module:babel-plugin-macros",
]
}
1 change: 1 addition & 0 deletions packages/putout/.gitignore
@@ -0,0 +1 @@
dist
5 changes: 5 additions & 0 deletions packages/putout/.webpack/index.js
@@ -0,0 +1,5 @@
'use strict';

require('module');
module.exports = require('../lib/putout');

7 changes: 7 additions & 0 deletions packages/putout/.webpack/module.js
@@ -0,0 +1,7 @@
'use strict';

module.exports._findPath = (a) => a;

const codegen = require('codegen.macro');
module.exports.plugins = codegen`module.exports = require('./require-all')();`;

18 changes: 18 additions & 0 deletions packages/putout/.webpack/require-all.js
@@ -0,0 +1,18 @@
'use strict';

const {plugins} = require('../putout.json');

module.exports = () => {
const result = plugins
.map((a) => `plugins['${a}'] = require('@putout/plugin-${a}');`)
.join('\n');

return `
const plugins = {};
${result};
return plugins;
`
};

65 changes: 65 additions & 0 deletions packages/putout/.webpack/webpack.config.js
@@ -0,0 +1,65 @@
'use strict';

const path = require('path');
const webpack = require('webpack');
const dir = './lib';

const {env} = process;
const isDev = env.NODE_ENV === 'development';

const dist = path.resolve(__dirname, '..', 'dist');
const distDev = path.resolve(__dirname, '..', 'dist-dev');
const devtool = isDev ? 'eval' : 'source-map';

const babelDev = {
plugins: [
'module:babel-plugin-macros',
],
};

const rules = [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: babelDev,
}];

module.exports = {
devtool,
entry: {
putout: path.join(__dirname, `./index.js`),
},
output: {
library: 'putout',
filename: '[name].js',
path: isDev ? distDev : dist,
pathinfo: isDev,
libraryTarget: 'umd',
devtoolModuleFilenameTemplate,
},
plugins: [
new webpack.IgnorePlugin({
checkResource(context) {
return /^esprima|fixture|^acorn|espree|tape|@putout\/test/.test(context);
},
}),
],
module: {
rules,
},
resolve: {
alias: {
module: path.resolve(__dirname, 'module.js'),
}
},
performance: {
maxEntrypointSize: 1024000,
maxAssetSize: 1024000,
},
};

function devtoolModuleFilenameTemplate(info) {
const resource = info.absoluteResourcePath.replace(__dirname + path.sep, '');
return `file://putout/${resource}`;
}

6 changes: 6 additions & 0 deletions packages/putout/lib/get-plugins/index.js
Expand Up @@ -113,6 +113,12 @@ function requirePlugin(name, fn) {
userPlugin,
];

if (Module.plugins && Module.plugins[name])
return [
name,
Module.plugins[name],
];

throw Error(`Plugin "putout-plugin-${name} could not be found!`);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/putout/madrun.js
Expand Up @@ -8,6 +8,10 @@ const lintScripts = [
];

module.exports = {
"prepublishOnly": () => run('build'),
'build:base': () => 'webpack --config ./.webpack/webpack.config.js',
'build': () => run('build:base', '--mode production'),
'build:dev': () => run('build:base', '--mode development'),
'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`,
'watch:test': () => `nodemon -w lib -w test -x ${run('test')}`,
'lint:lib': () => `eslint lib`,
Expand Down
18 changes: 15 additions & 3 deletions packages/putout/package.json
Expand Up @@ -13,12 +13,18 @@
"url": "git://github.com/coderaiser/putout.git"
},
"scripts": {
"prepublishOnly": "madrun prepublishOnly",
"build:base": "madrun build:base",
"build": "madrun build",
"build:dev": "madrun build:dev",
"test": "madrun test",
"watch:test": "madrun watch:test",
"lint:lib": "madrun lint:lib",
"lint:test": "madrun lint:test",
"lint:bin": "madrun lint:bin",
"lint": "madrun lint",
"fix:lint": "madrun fix:lint",
"putout": "bin/putout.js bin lib test",
"putout:fix": "bin/putout.js --fix bin lib test",
"putout": "madrun putout",
"coverage": "madrun coverage",
"report": "madrun report"
},
Expand Down Expand Up @@ -86,10 +92,14 @@
"unused"
],
"devDependencies": {
"@babel/core": "^7.4.5",
"@cloudcmd/stub": "^2.3.1",
"acorn": "^6.1.1",
"acorn-jsx": "^5.0.1",
"acorn-stage3": "^2.0.0",
"babel-loader": "^8.0.6",
"babel-plugin-macros": "^2.6.1",
"codegen.macro": "^3.0.0",
"coveralls": "^3.0.0",
"eslint": "^6.0.0-rc.0",
"eslint-plugin-node": "^8.0.1",
Expand All @@ -101,7 +111,9 @@
"mock-require": "^3.0.2",
"nodemon": "^1.14.12",
"nyc": "^14.0.0",
"supertape": "^1.0.3"
"supertape": "^1.0.3",
"webpack": "^4.34.0",
"webpack-cli": "^3.3.4"
},
"license": "MIT",
"engines": {
Expand Down

0 comments on commit d0652b1

Please sign in to comment.