次の karma.conf があります...
var webpackConfig = require('./webpack.common.js');
webpackConfig.entry = {};
webpackConfig.plugins = [];
var globFlat = require('glob-flat');
var appFiles = globFlat.sync([
'./src/main/coffee/**/*Module.coffee',
'./src/main/coffee/**/*.coffee'
]);
var styleFiles = globFlat.sync([
]);
var dependencyFiles = [
'./src/main/typescripts/*.ts',
];
var testFiles = globFlat.sync([
'./test/main/**/*.coffee',
'./test/main/**/*.js'
]);
var files = dependencyFiles.concat(appFiles, styleFiles, testFiles);
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'requirejs', 'chai-spies', 'chai'],
files: files,
preprocessors: {
'../src/main/coffee/**/*.coffee': ['webpack'],
'../src/main/typescripts/**/*.ts': ['webpack'],
'../src/test/**/*.coffee': ['coffee']
},
webpack: webpackConfig,
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
};
そして次のwebpack...
var webpack = require("webpack");
var glob = require('glob-all');
const helpers = require('./helpers');
var path = require("path");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var environment = process.env.NODE_ENV || 'development';
module.exports = function(options){
console.log("Running in " + environment+ " mode");
isProd = options.env === 'production';
return {
context: helpers.root(''),
entry: {
... // Shouldn't matter since it is overridden
},
resolve: {
extensions: ['', '.js', '.ts', '.coffee', '.pug', '.styl', '.less', '.css'],
modules: [helpers.root('src'), 'node_modules']
},
output: {
filename: "[name].js",
path: path.join(helpers.root(''), "src/main/webapp")
},
module: {
loaders: [
{test: /\.pug$/, loader: "pug-html-loader"},
{test: /\.ts$/, loader: 'ts'},
{
test: /\.coffee$/,
loaders: ["coffee-loader", "coffee-import"]
},
{test: /\.html$/, loader: "html?interpolate=require&-minimize"},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader"
},
{test: /\.css$/, loader: "style-loader!css-loader"},
// I have to add the regex .*? because some of the files are named like... fontello.woff2?952370
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?.*)?$/,
loader: 'url?limit=900000'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: helpers.root('src/main/html/index.html')
})
]
}
};
でも走ると何故かkarma run
…
Chrome 53.*** (Mac OS X ***) ERROR
Uncaught SyntaxError: Unexpected token import
at src/main/typescripts/polyfills.ts:1
私が作れば
preprocessors: {
'../src/main/coffee/**/*.coffee': ['webpack'],
'../src/main/typescripts/**/*.ts': ['webpack'],
'../src/test/**/*.coffee': ['coffee']
},
のようなものに...
preprocessors: {
'./src/main/coffee/**/*.coffee': ['webpack'],
'./src/main/typescripts/**/*.ts': ['webpack'],
'./src/test/**/*.coffee': ['coffee']
},
私は得る
パス: '/_karma_webpack_/src/main/coffee/utilities/view/My.coffee' }
エラー: そのようなファイルまたはディレクトリはありません
アップデート
わかりましたので、これが私の場合、webpackが実行されていないことを伝えることができる取引です。トランスパイルが機能しないのはそのためです。なぜですか?
私はこれをhttps://github.com/AngularClass/angular2-webpack-starterとほぼ同じように行っています。唯一のことは、カルマ conf を参照すると機能しないことですmodule.exports = require('./config/karma.conf.js');
。実際のカルマ conf をルート フォルダーに移動しても問題ないようです (現在は にありますsrc/build/karma.conf.js
) 。
更新 2
webpack.test.js をルート フォルダーに移動しようとし、そのファイルを再度使用するように構成しようとしましたが、それでも失敗するため、webpack.config.js に戻る必要があります。
webpack.test.js
// TODO: I would like this in the source folder but karma-webpack fails
const webpack = require("webpack");
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
const commonConfig = require('./src/build/webpack.common.js'); // the settings that are common to prod and dev
const glob = require('glob-all');
const tests = glob.sync([
'./src/test/webapp/**/*.coffee'
]);
const ENV = process.env.ENV = process.env.NODE_ENV = 'test';
module.exports = function (options) {
return webpackMerge(commonConfig({env: ENV}), {
entry: {
tests: '../src/test/**/*.coffee'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['tests', 'styles', 'app', 'vendor', 'polyfills'],
minChunks: Infinity
})
]
})
};
webpack.config.js
var environment = process.env.NODE_ENV || 'development';
switch (environment) {
case 'prod':
case 'production':
module.exports = require('./src/build/webpack.prod')({env: 'production'});
break;
case 'test':
case 'testing':
module.exports = require('./webpack.test.js')({env: 'test'});
break;
case 'dev':
case 'development':
module.exports = require('./src/build/webpack.dev')({env: 'development'});
break;
default:
module.exports = require('./src/build/webpack.common')({env: 'common'});