Skip to content

Commit b9c76e5

Browse files
committed
fix(webpack): copy environment file on build
closes #714
1 parent 0525dca commit b9c76e5

File tree

7 files changed

+89
-9
lines changed

7 files changed

+89
-9
lines changed

lib/commands/new/buildsystems/webpack/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ module.exports = function(project, options) {
3636
ProjectItem.resource('build.ext', 'tasks/build-webpack.ext', project.model.transpiler),
3737
ProjectItem.resource('build.json', 'tasks/build.json'),
3838
ProjectItem.resource('run.ext', 'tasks/run-webpack.ext', project.model.transpiler),
39-
ProjectItem.resource('run.json', 'tasks/run-webpack.json')
39+
ProjectItem.resource('run.json', 'tasks/run-webpack.json'),
40+
ProjectItem.resource('environment.ext', 'tasks/environment.ext', project.model.transpiler),
4041
).addToContent(
4142
ProjectItem.resource('index.ejs', 'content/index-webpack.ejs'),
4243
ProjectItem.resource('package-scripts.js', 'content/package-scripts.template.js')
@@ -45,6 +46,7 @@ module.exports = function(project, options) {
4546
ProjectItem.resource('webpack.config.js', 'content/webpack.config.template.js')
4647
.asTemplate(model)
4748
).addToDevDependencies(
49+
'gulp-rename',
4850
'html-webpack-plugin',
4951
'copy-webpack-plugin',
5052
'extract-text-webpack-plugin',

lib/resources/tasks/build-webpack.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import webpackConfig from '../../webpack.config';
22
import webpack from 'webpack';
33
import project from '../aurelia.json';
44
import {CLIOptions, Configuration} from 'aurelia-cli';
5+
import gulp from 'gulp';
6+
import configureEnvironment from './environment';
57

68
const buildOptions = new Configuration(project.build.options);
79
const production = CLIOptions.getEnvironment() === 'prod';
@@ -14,7 +16,7 @@ const config = webpackConfig({
1416
});
1517
const compiler = webpack(config);
1618

17-
function build(done) {
19+
function buildWebpack(done) {
1820
compiler.run(onBuild);
1921
compiler.plugin('done', () => done());
2022
}
@@ -29,7 +31,13 @@ function onBuild(err, stats) {
2931
}
3032
}
3133

34+
const build = gulp.series(
35+
configureEnvironment,
36+
buildWebpack
37+
);
38+
3239
export {
3340
config,
41+
buildWebpack,
3442
build as default
3543
};

lib/resources/tasks/build-webpack.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as webpackConfig from '../../webpack.config';
22
import * as webpack from 'webpack';
33
import * as project from '../aurelia.json';
44
import {CLIOptions, Configuration} from 'aurelia-cli';
5+
import * as gulp from 'gulp';
6+
import configureEnvironment from './environment';
57

68
const buildOptions = new Configuration(project.build.options);
79
const production = CLIOptions.getEnvironment() === 'prod';
@@ -14,7 +16,7 @@ const config = webpackConfig({
1416
});
1517
const compiler = webpack(config);
1618

17-
function build(done) {
19+
function buildWebpack(done) {
1820
compiler.run(onBuild);
1921
compiler.plugin('done', () => done());
2022
}
@@ -29,7 +31,13 @@ function onBuild(err, stats) {
2931
}
3032
}
3133

34+
const build = gulp.series(
35+
configureEnvironment,
36+
buildWebpack
37+
);
38+
3239
export {
3340
config,
41+
buildWebpack,
3442
build as default
3543
};

lib/resources/tasks/environment.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import project from '../aurelia.json';
2+
import rename from 'gulp-rename';
3+
import {CLIOptions} from 'aurelia-cli';
4+
import gulp from 'gulp';
5+
import fs from 'fs';
6+
import path from 'path';
7+
import through from 'through2';
8+
9+
function configureEnvironment() {
10+
let env = CLIOptions.getEnvironment();
11+
12+
return gulp.src(`aurelia_project/environments/${env}${project.transpiler.fileExtension}`)
13+
.pipe(rename(`environment${project.transpiler.fileExtension}`))
14+
.pipe(gulp.dest(project.paths.root))
15+
.pipe(through.obj(function (file, enc, cb) {
16+
// https://github.com/webpack/watchpack/issues/25#issuecomment-287789288
17+
var now = Date.now() / 1000;
18+
var then = now - 10;
19+
fs.utimes(file.path, then, then, function (err) { if (err) throw err });
20+
cb(null, file);
21+
}));
22+
}
23+
24+
export default configureEnvironment;

lib/resources/tasks/environment.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as project from '../aurelia.json';
2+
import * as rename from 'gulp-rename';
3+
import {CLIOptions} from 'aurelia-cli';
4+
import * as gulp from 'gulp';
5+
import * as fs from 'fs';
6+
import path from 'path';
7+
import * as through from 'through2';
8+
9+
function configureEnvironment() {
10+
let env = CLIOptions.getEnvironment();
11+
12+
return gulp.src(`aurelia_project/environments/${env}${project.transpiler.fileExtension}`)
13+
.pipe(rename(`environment${project.transpiler.fileExtension}`))
14+
.pipe(gulp.dest(project.paths.root))
15+
.pipe(through.obj(function (file, enc, cb) {
16+
// https://github.com/webpack/watchpack/issues/25#issuecomment-287789288
17+
var now = Date.now() / 1000;
18+
var then = now - 10;
19+
fs.utimes(file.path, then, then, function (err) { if (err) throw err });
20+
cb(null, file);
21+
}));
22+
}
23+
24+
export default configureEnvironment;

lib/resources/tasks/run-webpack.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {config} from './build';
2+
import configureEnvironment from './environment';
23
import webpack from 'webpack';
34
import Server from 'webpack-dev-server';
45
import project from '../aurelia.json';
56
import {CLIOptions, reportWebpackReadiness} from 'aurelia-cli';
6-
import build from './build';
7+
import gulp from 'gulp';
8+
import {buildWebpack} from './build';
79

8-
function run(done) {
10+
function runWebpack(done) {
911
// https://webpack.github.io/docs/webpack-dev-server.html
1012
let opts = {
1113
host: 'localhost',
@@ -37,7 +39,7 @@ function run(done) {
3739
if (err) throw err;
3840

3941
if (opts.lazy) {
40-
build(() => {
42+
buildWebpack(() => {
4143
reportWebpackReadiness(opts);
4244
done();
4345
});
@@ -48,4 +50,9 @@ function run(done) {
4850
});
4951
}
5052

53+
const run = gulp.series(
54+
configureEnvironment,
55+
runWebpack
56+
);
57+
5158
export { run as default };

lib/resources/tasks/run-webpack.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {config} from './build';
2+
import configureEnvironment from './environment';
23
import * as webpack from 'webpack';
34
import * as Server from 'webpack-dev-server';
45
import * as project from '../aurelia.json';
56
import {CLIOptions, reportWebpackReadiness} from 'aurelia-cli';
6-
import build from './build';
7+
import * as gulp from 'gulp';
8+
import {buildWebpack} from './build';
79

8-
function run(done) {
10+
function runWebpack(done) {
911
// https://webpack.github.io/docs/webpack-dev-server.html
1012
let opts = {
1113
host: 'localhost',
@@ -37,7 +39,7 @@ function run(done) {
3739
if (err) throw err;
3840

3941
if (opts.lazy) {
40-
build(() => {
42+
buildWebpack(() => {
4143
reportWebpackReadiness(opts);
4244
done();
4345
});
@@ -48,4 +50,9 @@ function run(done) {
4850
});
4951
}
5052

53+
const run = gulp.series(
54+
configureEnvironment,
55+
runWebpack
56+
);
57+
5158
export { run as default };

0 commit comments

Comments
 (0)