Skip to content

Commit

Permalink
Merge pull request #78 from homer0/next
Browse files Browse the repository at this point in the history
v9.0.0
  • Loading branch information
homer0 committed Aug 1, 2019
2 parents f6deff3 + 51b3442 commit aca80ad
Show file tree
Hide file tree
Showing 29 changed files with 1,993 additions and 1,204 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
8
8.10
8 changes: 0 additions & 8 deletions README.md
Expand Up @@ -409,18 +409,10 @@ This is called after generating the configuration for a browser target productio

## Development

Before doing anything, install the repository hooks:

```bash
# You can either use npm or yarn, it doesn't matter
yarn run hooks
```

### NPM/Yarn Tasks

| Task | Description |
|-------------------------|-------------------------------------|
| `yarn run hooks` | Install the GIT repository hooks. |
| `yarn test` | Run the project unit tests. |
| `yarn run lint` | Lint the modified files. |
| `yarn run lint:full` | Lint the project code. |
Expand Down
147 changes: 79 additions & 68 deletions package.json
@@ -1,77 +1,88 @@
{
"name": "projext-plugin-webpack",
"description": "Allows projext to use webpack as a build engine.",
"homepage": "https://homer0.github.io/projext-plugin-webpack/",
"version": "8.0.3",
"repository": "homer0/projext-plugin-webpack",
"author": "Leonardo Apiwan (@homer0) <me@homer0.com>",
"license": "MIT",
"dependencies": {
"projext": "^6.0.6",
"wootils": "^2.3.0",
"jimple": "^1.5.0",
"fs-extra": "^8.0.1",
"extend": "^3.0.2",
"name": "projext-plugin-webpack",
"description": "Allows projext to use webpack as a build engine.",
"homepage": "https://homer0.github.io/projext-plugin-webpack/",
"version": "9.0.0",
"repository": "homer0/projext-plugin-webpack",
"author": "Leonardo Apiwan (@homer0) <me@homer0.com>",
"license": "MIT",
"dependencies": {
"projext": "^7.0.0",
"wootils": "^2.6.0",
"jimple": "^1.5.0",
"fs-extra": "^8.1.0",
"extend": "^3.0.2",

"webpack": "^4.34.0",
"webpack-cli": "^3.3.4",
"webpack-dev-server": "3.5.0",
"mini-css-extract-plugin": "0.7.0",
"html-webpack-plugin": "^3.2.0",
"script-ext-html-webpack-plugin": "^2.1.3",
"compression-webpack-plugin": "2.0.0",
"terser-webpack-plugin": "1.3.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"copy-webpack-plugin": "^5.0.3",
"core-js": "^3.1.4",
"regenerator-runtime": "0.13.3",

"@babel/core": "7.4.4",
"node-sass": "^4.12.0",
"webpack": "^4.38.0",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.7.2",
"mini-css-extract-plugin": "0.8.0",
"html-webpack-plugin": "^3.2.0",
"script-ext-html-webpack-plugin": "^2.1.4",
"compression-webpack-plugin": "^3.0.0",
"terser-webpack-plugin": "^1.4.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"copy-webpack-plugin": "^5.0.4",
"extra-watch-webpack-plugin": "^1.0.3",

"babel-loader": "^8.0.6",
"css-loader": "2.1.1",
"sass-loader": "^7.1.0",
"style-loader": "0.23.1",
"raw-loader": "2.0.0",
"file-loader": "3.0.1",
"url-loader": "1.1.2",
"resolve-url-loader": "^3.1.0",
"source-map-loader": "0.2.4",
"@babel/core": "7.5.5",
"node-sass": "^4.12.0",

"webpack-dev-middleware": "^3.7.0",
"webpack-hot-middleware": "^2.25.0",
"babel-loader": "^8.0.6",
"css-loader": "^3.1.0",
"sass-loader": "^7.1.0",
"style-loader": "0.23.1",
"raw-loader": "^3.1.0",
"file-loader": "^4.1.0",
"url-loader": "^2.1.0",
"resolve-url-loader": "^3.1.0",
"source-map-loader": "0.2.4",

"terser": "4.0.0",
"webpack-dev-middleware": "^3.7.0",
"webpack-hot-middleware": "^2.25.0",

"opener": "^1.5.1"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-node": "^9.1.0",
"@babel/preset-env": "7.4.4",
"jest-ex": "^6.0.1",
"jest-cli": "^24.8.0",
"jasmine-expect": "^4.0.1",
"jimpex": "^3.0.0",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "^1.0.0",
"esdoc-node": "^1.0.4",
"leasot": "^7.4.0",
"coveralls": "^3.0.4"
},
"engine-strict": true,
"engines": {
"node": ">=8.0.0",
"npm": ">=3.0.0"
},
"main": "src/index.js",
"scripts": {
"hooks": "./utils/hooks/install",
"test": "./utils/scripts/test",
"lint": "./utils/scripts/lint",
"lint:full": "./utils/scripts/lint-full",
"docs": "./utils/scripts/docs",
"todo": "./utils/scripts/todo"
"terser": "^4.1.2",

"opener": "^1.5.1"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^9.1.0",
"@babel/preset-env": "7.5.5",
"@babel/plugin-transform-runtime": "7.5.5",
"jest-ex": "^6.1.1",
"jest-cli": "^24.8.0",
"jasmine-expect": "^4.0.3",
"jimpex": "^4.0.1",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "^1.0.0",
"esdoc-node": "^1.0.4",
"leasot": "^8.0.0",
"coveralls": "^3.0.5",
"husky": "^3.0.2"
},
"engine-strict": true,
"engines": {
"node": ">=8.10.0",
"npm": ">=3.0.0"
},
"main": "src/index.js",
"husky": {
"hooks": {
"pre-commit": "./utils/hooks/pre-commit",
"post-merge": "./utils/hooks/post-merge"
}
},
"scripts": {
"test": "./utils/scripts/test",
"lint": "./utils/scripts/lint",
"lint:full": "./utils/scripts/lint-full",
"docs": "./utils/scripts/docs",
"todo": "./utils/scripts/todo"
}
}
3 changes: 3 additions & 0 deletions polyfill.js
@@ -0,0 +1,3 @@
/* eslint-disable */
import 'core-js/stable';
import 'regenerator-runtime/runtime';
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -38,6 +38,7 @@ const loadPlugin = (app) => {
'express',
'jimpex',
],
babelPolyfill: 'polyfill.js',
}));
// Register the main services of the build engine.
app.register(webpackConfiguration);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/index.js
@@ -1,7 +1,9 @@
const ProjextWebpackBundleRunner = require('./bundleRunner');
const ProjextWebpackOpenDevServer = require('./openDevServer');
const ProjextWebpackRuntimeDefinitions = require('./runtimeDefinitions');

module.exports = {
ProjextWebpackBundleRunner,
ProjextWebpackOpenDevServer,
ProjextWebpackRuntimeDefinitions,
};
137 changes: 137 additions & 0 deletions src/plugins/runtimeDefinitions/index.js
@@ -0,0 +1,137 @@
const ObjectUtils = require('wootils/shared/objectUtils');
const { DefinePlugin } = require('webpack');
/**
* This is a webpack plugin that works with `webpack.DefinePlugin` in order to reload all
* definitions when the bundle changes.
*/
class ProjextWebpackRuntimeDefinitions {
/**
* @param {Array} files The list of files that need to
* change in order to reload
* the definitions.
* @param {Function():Object} definitionsFn When this function is called,
* it should return the object
* with the definitions.
* @param {ProjextWebpackRuntimeDefinitionsOptions} [options={}] The options to customize the
* plugin instance.
* @throws {Error} If `files` is not an Array.
* @throws {Error} If `files` is empty.
* @throws {Error} If `definitionsFn` is not a function.
*/
constructor(files, definitionsFn, options = {}) {
if (!Array.isArray(files) || !files.length) {
throw new Error('You need to provide a valid files list');
}

if (typeof definitionsFn !== 'function') {
throw new Error('You need to provide a valid definitions function');
}

/**
* The list of files that need to change in order to reload the definitions.
* @type {Array}
* @access protected
* @ignore
*/
this._files = files;
/**
* The function that will generate the definitions.
* @type {Function():Object}
* @access protected
* @ignore
*/
this._definitionsFn = definitionsFn;
/**
* The options to customize the plugin instance.
* @type {ProjextWebpackRuntimeDefinitionsOptions}
* @access protected
* @ignore
*/
this._options = ObjectUtils.merge(
{
name: 'projext-webpack-plugin-runtime-definitions',
},
options
);
/**
* This is where the plugin will "refresh" the definitions when the bundle changes.
* @type {Object}
* @access protected
* @ignore
*/
this._values = {};
}
/**
* Get the options that customize the plugin instance.
* @return {ProjextWebpackRuntimeDefinitionsOptions}
*/
getOptions() {
return this._options;
}
/**
* This is called by webpack when the plugin is being processed. The method will create a new
* instance of `webpack.DefinePlugin` and set all the values as "runtime values", so they'll
* get evaluated every time the bundle is generated.
* The method will also tap into the `compile` hook, so this plugin can refresh the values (by
* calling the `definitionFn`) when the bundle is about to be generated.
* @param {Object} compiler The compiler information provided by webpack.
*/
apply(compiler) {
const plugin = new DefinePlugin(this._getDefinePluginSettings());
plugin.apply(compiler);
compiler.hooks.compile.tap(
this._options.name,
this._onCompilationStarts.bind(this)
);
}
/**
* Reloads the saved values on the instance by calling the `definitionsFn`.
* @access protected
* @ignore
*/
_reloadValues() {
this._values = this._definitionsFn();
return this._values;
}
/**
* Generates the settings for `webpack.DefinePlugin`. It basically creates a "runtime value" for
* each of the definitions keys and sets a function that will call this instance.
* @return {Object}
* @access protected
* @ignore
*/
_getDefinePluginSettings() {
const keys = Object.keys(this._reloadValues());
return keys.reduce(
(settings, key) => Object.assign({}, settings, {
[key]: DefinePlugin.runtimeValue(
() => this._getValue(key),
this._files
),
}),
{}
);
}
/**
* Get a single value from a definition already loaded.
* @param {string} key The definition key.
* @return {string}
* @access protected
* @ignore
*/
_getValue(key) {
return this._values[key];
}
/**
* This is called by webpack when the bundle compilation starts. The method just reloads the
* definition values on the instance so they'll be available when `webpack.DefinePlugin` tries
* to access them.
* @access protected
* @ignore
*/
_onCompilationStarts() {
this._reloadValues();
}
}

module.exports = ProjextWebpackRuntimeDefinitions;

0 comments on commit aca80ad

Please sign in to comment.