Skip to content

Commit

Permalink
Merge pull request #42 from Sydsvenskan:feature/include-source-maps
Browse files Browse the repository at this point in the history
CLI feature: include source maps
  • Loading branch information
voxpelli authored Jul 20, 2020
2 parents 9375494 + 8d3ac78 commit 2159d50
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ yarn-error.log
*.d.ts
/example/dist
/example/asset-versions.json
/example/asset-versions-sourcemaps.json

# Due to many complexities, allow yarn.lock
!yarn.lock
10 changes: 9 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const options = [
help: 'Name of output file',
helpArg: 'FILE',
'default': 'asset-versions.json'
},
{
names: ['source-maps', 's'],
type: 'bool',
help: 'Include source-map entries when adding WebPack files',
'default': false
}
];

Expand Down Expand Up @@ -62,6 +68,8 @@ if (opts.help) {
process.exit(0);
}

const includeSourceMaps = opts.source_maps;

delete opts._args;

const pathModule = require('path');
Expand Down Expand Up @@ -93,7 +101,7 @@ debug('resolved source dir: %s', resolvedSourceDir);

// Add all webpack files as well
Object.keys(webpackFiles).forEach(file => {
if (!file.endsWith('.map') && !files.includes(file)) {
if (!files.includes(file) && !(file.endsWith('.map') && !includeSourceMaps)) {
files.push(file);
}
});
Expand Down
28 changes: 28 additions & 0 deletions example/example-asset-versions-sourcemaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"files": {
"main.css": "dist/rev/main-1e0840afd5.css",
"main.js": "dist/rev/main.b0d2da5553e91f2eda06.js",
"internal.js": "dist/rev/internal.474af3f1b516bf419cc2.js",
"internal.js.map": "dist/rev/internal.474af3f1b516bf419cc2.js.map",
"lazy.js": "dist/rev/lazy.bfbca080e93a94fb8399.js",
"lazy.js.map": "dist/rev/lazy.bfbca080e93a94fb8399.js.map",
"main.js.map": "dist/rev/main.b0d2da5553e91f2eda06.js.map",
"runtime.js": "dist/rev/runtime.1f80a7f72d942962fd9d.js",
"runtime.js.map": "dist/rev/runtime.1f80a7f72d942962fd9d.js.map"
},
"dependencies": {
"main.js": [
"runtime.js",
"internal.js"
],
"internal.js": [
"runtime.js",
"main.js"
],
"lazy.js": [],
"runtime.js": [
"internal.js",
"main.js"
]
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
"url": "git://github.com/sydsvenskan/node-asset-versions.git"
},
"scripts": {
"build:01-make-folders": "mkdir -p example/dist/bare/",
"build:css": "cp example/src/main.css example/dist/bare/main.css",
"build:js": "webpack --mode='production' --devtool hidden-source-map --config example/webpack.config.js --output-public-path /dist/rev/",
"build": "run-p build:* && rm -rf example/dist/rev && node cli.js -p example",
"build": "run-p build:* && rm -rf example/dist/rev && node cli.js -p example && node cli.js -s -p example -o asset-versions-sourcemaps.json",
"check:dependency-check": "dependency-check *.js --no-dev -i @types/*",
"check:eslint": "eslint .",
"check:installed-check": "installed-check -i eslint",
"check:tsc": "tsc",
"start": "run-s build && node example/app.js",
"test:example:manifest": "diff --ignore-all-space example/example-manifest.json example/dist/bare/manifest.json",
"test:example:versions": "diff --ignore-all-space example/example-asset-versions.json example/asset-versions.json",
"test:example:sourcemaps": "diff --ignore-all-space example/example-asset-versions-sourcemaps.json example/asset-versions-sourcemaps.json",
"test:example": "run-s build && run-p test:example:*",
"test:mocha": "NODE_ENV=test nyc --reporter=lcov --reporter text mocha --reporter dot test/**/*.spec.js",
"test": "run-p check:* && run-p test:*"
Expand Down

0 comments on commit 2159d50

Please sign in to comment.