diff --git a/README.md b/README.md index e8ec017..62510fc 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,26 @@ $ npm install spm-webpack -g ``` ## Usage - ```bash $ spm-webpack [option] [file] ``` +## Added +add spm.build.publicPath args pass to webpack's output.publicPath +[webpack-configuration](https://github.com/webpack/docs/wiki/configuration#outputpublicpath) +```javascript +{ + "spm": { + "output": [ + "main.js" + ], + "build": { + "publicPath": "http://xxx.com/assets/" + } + } +} +``` + ## LISENCE Copyright (c) 2015-2114 chencheng. Licensed under the MIT license. diff --git a/lib/build.js b/lib/build.js index 2a853c3..c54d148 100644 --- a/lib/build.js +++ b/lib/build.js @@ -160,6 +160,7 @@ function getWebpackOpts(opts, callback) { }, output: { path: join(opts.build.dest || 'dist', utils.getPrefix(pkg)), + publicPath: opts.build.publicPath, filename: name + '.js', chunkFilename: name + '.js' }, diff --git a/lib/getArgs.js b/lib/getArgs.js index 63dd9ce..6254d55 100644 --- a/lib/getArgs.js +++ b/lib/getArgs.js @@ -7,6 +7,7 @@ var extend = require('extend'); var defaults = { build: { dest: 'dist', + publicPath:'', force: false, install: true, uglify: { diff --git a/test/build-spec.js b/test/build-spec.js index c4a87fb..c1473f7 100644 --- a/test/build-spec.js +++ b/test/build-spec.js @@ -37,6 +37,15 @@ describe('lib/build.js', function() { }); assert(dest, 'js-entry-umd'); }); + + it('arg-publicPath', function*() { + yield build({ + debug: true, + cwd: join(fixtures, 'arg-publicPath'), + dest: dest + }); + assert(dest, 'arg-publicPath'); + }); it('js entry with no package.json', function*() { yield build({ diff --git a/test/expected/arg-publicPath/1.js b/test/expected/arg-publicPath/1.js new file mode 100644 index 0000000..2da283e --- /dev/null +++ b/test/expected/arg-publicPath/1.js @@ -0,0 +1,12 @@ +webpackJsonp([1],{ + +/***/ 2: +/***/ function(module, exports) { + + + module.exports = 'b'; + + +/***/ } + +}); \ No newline at end of file diff --git a/test/expected/arg-publicPath/a.js b/test/expected/arg-publicPath/a.js new file mode 100644 index 0000000..b6f4105 --- /dev/null +++ b/test/expected/arg-publicPath/a.js @@ -0,0 +1,112 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // install a JSONP callback for chunk loading +/******/ var parentJsonpFunction = window["webpackJsonp"]; +/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) { +/******/ // add "moreModules" to the modules object, +/******/ // then flag all "chunkIds" as loaded and fire callback +/******/ var moduleId, chunkId, i = 0, callbacks = []; +/******/ for(;i < chunkIds.length; i++) { +/******/ chunkId = chunkIds[i]; +/******/ if(installedChunks[chunkId]) +/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]); +/******/ installedChunks[chunkId] = 0; +/******/ } +/******/ for(moduleId in moreModules) { +/******/ modules[moduleId] = moreModules[moduleId]; +/******/ } +/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules); +/******/ while(callbacks.length) +/******/ callbacks.shift().call(null, __webpack_require__); + +/******/ }; + +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // object to store loaded and loading chunks +/******/ // "0" means "already loaded" +/******/ // Array means "loading", array contains callbacks +/******/ var installedChunks = { +/******/ 0:0 +/******/ }; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + +/******/ // This file contains only the entry chunk. +/******/ // The chunk loading function for additional chunks +/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) { +/******/ // "0" is the signal for "already loaded" +/******/ if(installedChunks[chunkId] === 0) +/******/ return callback.call(null, __webpack_require__); + +/******/ // an array means "currently loading". +/******/ if(installedChunks[chunkId] !== undefined) { +/******/ installedChunks[chunkId].push(callback); +/******/ } else { +/******/ // start chunk loading +/******/ installedChunks[chunkId] = [callback]; +/******/ var head = document.getElementsByTagName('head')[0]; +/******/ var script = document.createElement('script'); +/******/ script.type = 'text/javascript'; +/******/ script.charset = 'utf-8'; +/******/ script.async = true; + +/******/ script.src = __webpack_require__.p + "" + ({}[chunkId]||chunkId) + ".js"; +/******/ head.appendChild(script); +/******/ } +/******/ }; + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = "some-path/"; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + module.exports = __webpack_require__(1); + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + + __webpack_require__.e/* require */(1, function(__webpack_require__) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [__webpack_require__(2)]; (function(b) { + console.log(b); + }.apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));}); + + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/test/fixtures/arg-publicPath/a.js b/test/fixtures/arg-publicPath/a.js new file mode 100644 index 0000000..f74cb79 --- /dev/null +++ b/test/fixtures/arg-publicPath/a.js @@ -0,0 +1,4 @@ + +require(['./b.js'], function(b) { + console.log(b); +}); diff --git a/test/fixtures/arg-publicPath/b.js b/test/fixtures/arg-publicPath/b.js new file mode 100644 index 0000000..7866c50 --- /dev/null +++ b/test/fixtures/arg-publicPath/b.js @@ -0,0 +1,2 @@ + +module.exports = 'b'; diff --git a/test/fixtures/arg-publicPath/package.json b/test/fixtures/arg-publicPath/package.json new file mode 100644 index 0000000..c38fe1b --- /dev/null +++ b/test/fixtures/arg-publicPath/package.json @@ -0,0 +1,10 @@ +{ + "spm": { + "build": { + "publicPath":"some-path/" + }, + "output": [ + "a.js" + ] + } +} \ No newline at end of file