, , manjor-.
https://gist.github.com/haydenbr/7df417a8678efc404c820c61b6ffdd24
, . , . , . , . , , . github.
, webpack package.json, .
package.json .
"config": {
"ionic_webpack": "./webpack.config.js",
"ionic_source_map_type": "source-map",
"ionic_uglifyjs": "./www/uglifyjs.config.json"
}
- . , , :
var path = require('path'),
fs = require('fs'),
ManifestPlugin = require('webpack-manifest-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin');
...
plugins: [
new HtmlWebpackPlugin({
filename: './../index.html',
inject: 'body',
template: './src/index.html',
title: 'My App',
}),
new ManifestPlugin(),
updateFileName
]
updateFileName
function updateFileName() {
this.plugin("done", function() {
var manifest = require(process.env.IONIC_BUILD_DIR + '/manifest.json'),
fileName = process.env.IONIC_OUTPUT_JS_FILE_NAME;
updateUglifyConfig(fileName, manifest);
process.env.IONIC_OUTPUT_JS_FILE_NAME = manifest[fileName];
});
}
function updateUglifyConfig(fileName, manifest) {
var uglifyConfig = {
sourceFile: manifest[fileName],
destFileName: manifest[fileName],
inSourceMap: manifest[fileName + '.map'],
outSourceMap: manifest[fileName + '.map'],
mangle: true,
compress: true,
comments: true
};
fs.writeFileSync(
path.join(__dirname, 'www', 'uglifyjs.config.json'),
JSON.stringify(uglifyConfig, null, 4)
);
}
, ? .json uglify . , process.env.IONIC_OUTPUT_JS_FILE_NAME, , , uglify - , main.js, , .
.
. . , index.html , , <script> javascript, , filename. index.html , , <script src="build/main.js"></script>, . .
, , . www/build/. .
- , process.env.IONIC_OUTPUT_JS_FILE_NAME uglify. , , uglify www, , .
, . , - dev, html pluggin, , process.env.IONIC_OUTPUT_JS_FILE_NAME. , js src/index.html. , dev prod. webpack .
UPDATE:
3:
- ,
compilerOptions tsconfig:
"module": "es2015", "target": "es5"
npm i cheerio --save-dev- webpack add
var cheerio = require('cheerio') - WebPack Manifest.
updateFileName :
function updateFileName() {
this.plugin("done", function(stats) {
var buildOutput = stats.toJson()['assetsByChunkName']['main'],
fileName = process.env.IONIC_OUTPUT_JS_FILE_NAME,
manifest = {
[fileName]: buildOutput[0],
[fileName + '.map']: buildOutput[1]
};
updateUglifyConfig(fileName, manifest);
process.env.IONIC_OUTPUT_JS_FILE_NAME = manifest[fileName];
console.log('IONIC_OUTPUT_JS_FILE_NAME', process.env.IONIC_OUTPUT_JS_FILE_NAME);
});
}
Html Webpack Plugin
html webpack:
function updateIndexHTML() {
this.plugin("done", function(stats) {
var buildOutput = stats.toJson()['assetsByChunkName']['main'],
outputFileName = buildOutput[0],
currentIndexHTML = fs.readFileSync(
path.join(__dirname, 'src', 'index.html'),
{ encoding: 'utf8' }
),
$ = cheerio.load(currentIndexHTML);
$('body').append(`<script src="build/${outputFileName}"></script>`);
fs.writeFileSync(
path.join(process.env.IONIC_WWW_DIR, 'index.html'),
$.html()
);
});
}