Skip to content

Instantly share code, notes, and snippets.

@ykzts
Created February 14, 2017 15:16
Show Gist options
  • Save ykzts/3fe28e567b7a14b632ec943827ea416e to your computer and use it in GitHub Desktop.
Save ykzts/3fe28e567b7a14b632ec943827ea416e to your computer and use it in GitHub Desktop.
PhantomJSで動かすことを前提とするスクリプトファイルをwebpackでバンドルするための`webpack.config.js` (と簡略化した`package.json`) です。
{
"babel": {
"babelrc": false,
"plugins": [
"transform-es2015-modules-commonjs"
]
},
"eslintConfig": {
"env": {
"browser": true,
"phantomjs": true
},
"extends": "airbnb-base"
},
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-async-to-generator": "^6.22.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-block-scoping": "^6.23.0",
"babel-plugin-transform-es2015-classes": "^6.23.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.23.0",
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-es2015-shorthand-properties": "^6.22.0",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"babel-plugin-transform-regenerator": "^6.22.0",
"babel-polyfill": "^6.23.0",
"cross-env": "^3.1.4",
"eslint": "^3.15.0",
"eslint-config-airbnb-base": "^11.1.0",
"eslint-plugin-import": "^2.2.0",
"npm-run-all": "^4.0.1",
"webpack": "^2.2.1"
},
"private": true,
"scripts": {
"build": "cross-env NODE_ENV=production webpack",
"dev": "cross-env NODE_ENV=development webpack --watch",
"lint": "eslint --ext js .",
"prestart": "npm-run-all build",
"start": "phantomjs build/crawler.js"
}
}
import path from 'path';
const babelrc = {
plugins: [
'transform-async-to-generator',
'transform-es2015-arrow-functions',
'transform-es2015-block-scoping',
'transform-es2015-classes',
'transform-es2015-destructuring',
'transform-es2015-parameters',
'transform-es2015-shorthand-properties',
'transform-es2015-spread',
'transform-es2015-template-literals',
'transform-regenerator',
],
};
const crawlerConfig = {
entry: {
crawler: [
'babel-polyfill',
path.resolve(__dirname, 'src', 'crawler.js'),
],
},
externals: [
{
webpage: 'commonjs webpage',
},
],
module: {
rules: [
{
exclude: path.resolve(__dirname, 'node_modules'),
test: /\.js$/,
use: {
loader: 'babel-loader',
options: Object.assign({
babelrc: false,
}, babelrc),
},
},
],
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'build'),
},
};
export default crawlerConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment