-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from luisaph/upgrade-node-magicbook
Upgrade node magicbook
- Loading branch information
Showing
10 changed files
with
1,065 additions
and
1,485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,18 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/[email protected] | ||
# with: | ||
# ref: master | ||
uses: actions/checkout@v4 | ||
with: | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '14.18.0' | ||
node-version: '20.0.0' | ||
cache: 'yarn' | ||
|
||
- name: Enable Corepack | ||
run: corepack enable | ||
|
||
- name: Install and Build 🔧 | ||
run: | | ||
yarn install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const webpack = require("webpack"); | ||
const fs = require('fs'); | ||
const _ = require("lodash"); | ||
const path = require('path'); | ||
const util = require('util'); | ||
const through = require('through2'); | ||
|
||
const Plugin = function(registry) { | ||
registry.before('load', 'webpack:run', this.run); | ||
registry.before('liquid', 'webpack:insert', this.insert); | ||
} | ||
|
||
Plugin.prototype = { | ||
|
||
// Run webpack and put the resulting output into a | ||
// manifest object | ||
run: function(config, extras, callback) { | ||
|
||
// If the configuration file has a webpack property | ||
// with a link to the config file | ||
if(config.webpack) { | ||
|
||
const that = this; | ||
this.manifest = {}; | ||
|
||
// Require the config file relative to the process | ||
// and make a copy to not mess up between tests. | ||
const loadPath = path.join(process.cwd(), config.webpack); | ||
const conf = _.cloneDeep(require(loadPath)); | ||
|
||
// Entries should be loaded relative to the config file | ||
conf.context = path.dirname(loadPath); | ||
|
||
// Output should be relative to the build folder | ||
const oldPath = conf.output.path; | ||
conf.output.path = path.join(process.cwd(), extras.destination, oldPath); | ||
|
||
|
||
// Run webpack | ||
webpack(conf, function(err, stats) { | ||
if(err) return callback(err, config, extras); | ||
|
||
const json = stats.toJson(); | ||
|
||
if(json.errors.length > 0) console.error(json.errors); | ||
if(json.warnings.length > 0) console.warn(json.warnings); | ||
|
||
|
||
// Parse output files into a manifest object | ||
_.each(json.assetsByChunkName, function(v, k) { | ||
that.manifest[k] = path.join(oldPath, v.toString()); | ||
}); | ||
|
||
callback(null, config, extras); | ||
}); | ||
|
||
} else { | ||
callback(null, config, extras); | ||
} | ||
}, | ||
|
||
// Loop through each file and add the relative link to the | ||
// manifest files. | ||
insert: function(config, stream, extras, callback) { | ||
|
||
const manifest = this.manifest; | ||
|
||
// add the locals to the files liquidLocals | ||
stream = stream.pipe(through.obj(function(file, enc, cb) { | ||
|
||
_.each(manifest, function(filename, k) { | ||
const rel = path.relative(path.dirname(file.relative), filename); | ||
_.set(file, 'layoutLocals.webpack.' + k, rel); | ||
_.set(file, 'pageLocals.webpack.' + k, rel); | ||
}); | ||
|
||
cb(null, file); | ||
})); | ||
|
||
callback(null, config, stream, extras); | ||
} | ||
} | ||
|
||
module.exports = Plugin; |
Oops, something went wrong.