Skip to content

Commit

Permalink
feat(webpack): import behavior for non-iife fomat usage
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Feb 17, 2016
1 parent cd60a4c commit fbbce5e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
23 changes: 20 additions & 3 deletions lib/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function (type, options) {
devtool: type === 'watch' ? 'cheap-module-eval-source-map' : 'source-map',
entry: options.entry ? objectString(options.entry) : 'src/index',
output: {
path: cwd('build'),
path: cwd(options.dest || 'build'),
filename: 'bundle.js',
publicPath: './'
},
Expand Down Expand Up @@ -96,14 +96,31 @@ module.exports = function (type, options) {
fallbacks: true
})
],
plugins: [
plugins: []
}
// for both watch and build
// set format
if (options.format === 'umd') {
config.output.libraryTarget = 'umd'
config.output.library = options.umd
} else if (options.format === 'cjs') {
config.output.libraryTarget = 'commonjs2'
}
// set target
if (options.target) {
config.target = options.target
}
// add html plugin if not targeted in commonjs
if (options.format !== 'cjs') {
config.plugins.push(
new HtmlWebpackPlugin(Object.assign({}, {
title: options.title || 'Tooling',
template: dir('lib/index.jade'),
inject: false
}, toolingConfig.index))
]
)
}

if (type === 'watch') {
// inject client page for hmr
if (typeof config.entry === 'string') {
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ Options:
|-u/--use|Set the framework you use, eg: `react`, `vue`. `vue` by default|
|--ai/--auto-install|(**Buggy**) Automatically install missing dependencies when editing|
|--title|Set html title|
|--format|Set bundle format, available options are `cjs` `umd`, default is `iife`|
|-t/--target|Set webpack target|
|-d/--dest|Set bundled file dest directory, default is `./build`|

Run `tooling -h` `tooling watch -h` `tooling build -h` to see more usage.

**Set up custom index.html in `package.json`**. see usage at [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin)

Expand All @@ -82,7 +87,7 @@ Options:
"tooling": {
"index": {
"title": "tooling index",
"template": "src/index.template"
"template": "src/index.jade"
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions tooling
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ program.version(pkg.version)

program
.command('watch')
.description('hot reloading mode')
.option('-e, --entry [webpackEntry]', 'Set webpack entry')
.option('-p, --port [serverPort]', 'Change port of server')
.option('--bs, --browser-sync [port]', 'Toggle browserSync')
.option('-s, --silent', 'Do not open browser window')
.option('-u, --use [usePresetsFor]', 'Use presets for React or Vue or the default config')
.option('--ai, --auto-install', 'Automatically install missing dependencies when editing')
.option('--title [htmlTitle]', 'Set title for output html')
.option('--format [bundleFormat]', 'Set bundle format')
.option('--target [webpackTarget]', 'Set webpack target')
.action(watch)

program
.command('build')
.description('build mode')
.option('-e, --entry [webpackEntry]', 'Set webpack entry"')
.option('-u, --use [usePresetsFor]', 'Use presets for React or Vue')
.option('--title [htmlTitle]', 'Set title for output html')
.option('--format [bundleFormat]', 'Set bundle format')
.option('-t, --target [webpackTarget]', 'Set webpack target')
.option('-d, --dest [bundleDestDir]', 'Set bundled file dest directory')
.action(build)

program.parse(process.argv)

0 comments on commit fbbce5e

Please sign in to comment.